On Sat, Jul 5, 2025 at 8:24 AM Ge <evergon...@gmail.com> wrote:
>
> As follows showing,  when `-N` is enabled with compiler, it gives the 
> expected output.
> ```
> ➜  grd more nf2.go
> package main
>
> import "os"
>
> func main() {
>         f, err := os.Open("nonExistFile")
>         fname := f.Name()
>         if err != nil {
>                 println("failed to open file, Error:", err.Error())
>                 return
>         }
>
>         println("filename:", fname)
> }
> ➜  grd go run nf2.go
> failed to open file, Error: open nonExistFile: no such file or directory
>
> ➜  grd go run -gcflags="-N" nf2.go
> panic: runtime error: invalid memory address or nil pointer dereference
> [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4782e3]
>
> goroutine 1 [running]:
> os.(*File).Name(...)
>         /usr/local/go/src/os/file.go:62
> main.main()
>         /root/grd/nf2.go:7 +0x123
> exit status 2
>
> ➜  grd go version
> go version go1.24.4 linux/amd64
> ```

This may be https://go.dev/issue/72860. In any case, it works
correctly (that is, it panics) on HEAD and the upcoming Go 1.25
release.

Ian

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
To view this discussion visit 
https://groups.google.com/d/msgid/golang-nuts/CAOyqgcU-_Hp0%3D5bTAGuF76BgTxub%2BGpV4oypDAGbT3YSyoWemQ%40mail.gmail.com.

Reply via email to