We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I run this code:
package foo type Foo struct { x []int } func NewFoo() Foo { return Foo{} } func Main() int { foo := NewFoo() if foo.x == nil { return 1 } return 0 }
I expect to get 1 but got panic during compilation. If I use return Foo{x:nil} panic does not occur and I got correct result.
1
return Foo{x:nil}
Panic message:
panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x8098fb] goroutine 19 [running]: testing.tRunner.func1.1(0x891a80, 0xcd5eb0) /snap/go/current/src/testing/testing.go:940 +0x2f5 testing.tRunner.func1(0xc0000d37a0) /snap/go/current/src/testing/testing.go:943 +0x3f9 panic(0x891a80, 0xcd5eb0) /snap/go/current/src/runtime/panic.go:969 +0x166 github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).emitLoadConst(0xc0000e9e00, 0x0, 0x0, 0x0, 0x0, 0x0) /home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:115 +0x4b github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).convertStruct(0xc0000e9e00, 0xc0000acc80) /home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:1211 +0x25a github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).Visit(0xc0000e9e00, 0x9c4be0, 0xc0000acc80, 0x0, 0x0) /home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:568 +0x1382 go/ast.Walk(0x9c1780, 0xc0000e9e00, 0x9c4be0, 0xc0000acc80) /snap/go/current/src/go/ast/walk.go:52 +0x66 github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).Visit(0xc0000e9e00, 0x9c52a0, 0xc0000b7060, 0xc000099660, 0x0) /home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:437 +0x33cf go/ast.Walk(0x9c1780, 0xc0000e9e00, 0x9c52a0, 0xc0000b7060) /snap/go/current/src/go/ast/walk.go:52 +0x66 go/ast.walkStmtList(0x9c1780, 0xc0000e9e00, 0xc000099410, 0x1, 0x1) /snap/go/current/src/go/ast/walk.go:32 +0x9e go/ast.Walk(0x9c1780, 0xc0000e9e00, 0x9c49e0, 0xc00009de00) /snap/go/current/src/go/ast/walk.go:224 +0x1adf github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).convertFuncDecl(0xc0000e9e00, 0x9c4de0, 0xc0000ee180, 0xc00009de30) /home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:263 +0x542 github.com/nspcc-dev/neo-go/pkg/compiler.(*codegen).compile(0xc0000e9e00, 0xc0000b73a0, 0xc0000c0370, 0xc0000a5230, 0x0) /home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:1317 +0x490 github.com/nspcc-dev/neo-go/pkg/compiler.CodeGen(0xc0000b73a0, 0xc0000b6f20, 0xc0000b73a0, 0x0, 0x0, 0xc00009dc01, 0xc0000b6f20) /home/alexvanin/Project/Neo/neo-go/pkg/compiler/codegen.go:1345 +0x289 github.com/nspcc-dev/neo-go/pkg/compiler.CompileWithDebugInfo(0x9c1d60, 0xc0000b6f20, 0x7f8a774707d0, 0x0, 0x40e0e6, 0xc0000b6ee0, 0x20, 0x20) /home/alexvanin/Project/Neo/neo-go/pkg/compiler/compiler.go:78 +0x90 github.com/nspcc-dev/neo-go/pkg/compiler.Compile(...) /home/alexvanin/Project/Neo/neo-go/pkg/compiler/compiler.go:64 github.com/nspcc-dev/neo-go/pkg/compiler_test.vmAndCompileInterop(0xc0000d37a0, 0x92f6bc, 0xae, 0xc0000a5150, 0xc000044738) /home/alexvanin/Project/Neo/neo-go/pkg/compiler/vm_test.go:66 +0x10b github.com/nspcc-dev/neo-go/pkg/compiler_test.vmAndCompile(...) /home/alexvanin/Project/Neo/neo-go/pkg/compiler/vm_test.go:56 github.com/nspcc-dev/neo-go/pkg/compiler_test.eval(0xc0000d37a0, 0x92f6bc, 0xae, 0x90bb00, 0xc0000b6ee0) /home/alexvanin/Project/Neo/neo-go/pkg/compiler/vm_test.go:33 +0x49 github.com/nspcc-dev/neo-go/pkg/compiler_test.TestForLoopRangeGlobalIndex1(0xc0000d37a0) /home/alexvanin/Project/Neo/neo-go/pkg/compiler/for_test.go:486 +0x7d testing.tRunner(0xc0000d37a0, 0x936d68) /snap/go/current/src/testing/testing.go:991 +0xdc created by testing.(*T).Run /snap/go/current/src/testing/testing.go:1042 +0x357
The text was updated successfully, but these errors were encountered:
branch: master-2.x version: 0.74.1-pre-156-gc85e77e1
Sorry, something went wrong.
See my first comment to #952.
Fixed via #952 .
fyrchik
No branches or pull requests
I run this code:
I expect to get
1
but got panic during compilation. If I usereturn Foo{x:nil}
panic does not occur and I got correct result.Panic message:
The text was updated successfully, but these errors were encountered: