This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> go install github.com/mlowicki/lab && ./bin/lab | |
Before defer statement | |
After defer statement | |
panic: runtime error: invalid memory address or nil pointer dereference | |
[signal 0xb code=0x1 addr=0x0 pc=0x549b3] | |
goroutine 1 [running]: | |
panic(0xda6c0, 0x8201c80e0) | |
/usr/local/go/src/runtime/panic.go:481 +0x3e6 | |
main.main() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
f := func() {} | |
f = nil | |
fmt.Println("Before defer statement") | |
defer f() | |
fmt.Println("After defer statement") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
type T struct{} | |
func (t T) m() { | |
fmt.Println("Inside method") | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> go install github.com/mlowicki/lab && ./bin/lab | |
3 | |
2 | |
1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
defer func() { | |
fmt.Println("1") | |
}() | |
defer func() { | |
fmt.Println("2") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> go install github.com/mlowicki/lab && ./bin/lab | |
Inside f, n=1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func main() { | |
f := func(n int) { | |
fmt.Printf("Inside f, n=%d\n", n) | |
} | |
n := 1 | |
defer f(n) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> go install github.com/mlowicki/lab && ./bin/lab | |
1 | |
2 | |
Inside deferred function | |
panic: boom! | |
goroutine 1 [running]: | |
panic(0xb8260, 0x8202301f0) | |
/usr/local/go/src/runtime/panic.go:481 +0x3e6 | |
main.f() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func f() { | |
fmt.Println("1") | |
defer func() { | |
fmt.Println("Inside deferred function") | |
}() | |
fmt.Println("2") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
> go install github.com/mlowicki/lab && ./bin/lab | |
1 | |
2 | |
Inside deferred function |