Skip to content

Commit 3309658

Browse files
randall77gopherbot
authored andcommitted
doc: document change in nil-ptr checking behavior
This could bite people during the 1.25 release, so make sure it has good documentation in the release notes. Update #72860 Change-Id: Ie9aaa219025a631e81ebc48461555c5fb898f43f Reviewed-on: https://go-review.googlesource.com/c/go/+/658955 Reviewed-by: Jorropo <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Reviewed-by: Keith Randall <[email protected]> Auto-Submit: Keith Randall <[email protected]> LUCI-TryBot-Result: Go LUCI <[email protected]>
1 parent bfb27fb commit 3309658

File tree

1 file changed

+29
-0
lines changed

1 file changed

+29
-0
lines changed

doc/next/5-toolchain.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,35 @@ information in Go binaries.
99
DWARF 5 generation is gated by the "dwarf5" GOEXPERIMENT; this
1010
functionality can be disabled (for now) using GOEXPERIMENT=nodwarf5.
1111

12+
<!-- https://go.dev/issue/72860, CL 657715 -->
13+
14+
The compiler [has been fixed](/cl/657715)
15+
to ensure that nil pointer checks are performed promptly. Programs like the following,
16+
which used to execute successfully, will now panic with a nil-pointer exception:
17+
18+
```
19+
package main
20+
21+
import "os"
22+
23+
func main() {
24+
f, err := os.Open("nonExistentFile")
25+
name := f.Name()
26+
if err != nil {
27+
return
28+
}
29+
println(name)
30+
}
31+
```
32+
33+
This program is incorrect in that it uses the result of `os.Open` before checking
34+
the error. The main result of `os.Open` can be a nil pointer if the error result is non-nil.
35+
But because of [a compiler bug](/issue/72860), this program ran successfully under
36+
Go versions 1.21 through 1.24 (in violation of the Go spec). It will no longer run
37+
successfully in Go 1.25. If this change is affecting your code, the solution is to put
38+
the non-nil error check earlier in your code, preferrably immediately after
39+
the error-generating statement.
40+
1241
## Assembler {#assembler}
1342

1443
## Linker {#linker}

0 commit comments

Comments
 (0)