Skip to content
New issue

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

go/types: assertion failure in expr.go:978 (Checker.rawExpr) #20837

Closed
griesemer opened this issue Jun 28, 2017 · 5 comments
Closed

go/types: assertion failure in expr.go:978 (Checker.rawExpr) #20837

griesemer opened this issue Jun 28, 2017 · 5 comments
Assignees
Milestone

Comments

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jun 28, 2017

To reproduce:

  1. On top of commit e6d9eda2fc13786c55292429b510128252ad8817, apply
    https://go-review.googlesource.com/#/c/43512/:
    git fetch https://go.googlesource.com/go refs/changes/12/43512/8 && git cherry-pick FETCH_HEAD

  2. cd $GOROOT/src; GOOS=linux GOARCH=s390x CGO_ENABLED=0 go tool vet -unsafeptr=false -source archive/zip

Crash (after augmenting go/types to print a bit more information):

vet: import failed: type-checking package "fmt" failed (/Users/gri/go/src/fmt/print.go:10:2: could not import os (type-checking package "os" failed (/Users/gri/go/src/os/dir_unix.go:12:2: could not import syscall (type-checking package "syscall" failed (/Users/gri/go/src/syscall/zerrors_linux_s390x.go:889:2: PR_CAP_AMBIENT redeclared in this block)))))
vet: import failed: type-checking package "fmt" failed (/Users/gri/go/src/fmt/print.go:10:2: could not import os (type-checking package "os" failed (/Users/gri/go/src/os/dir_unix.go:12:2: could not import syscall (type-checking package "syscall" failed (/Users/gri/go/src/syscall/zerrors_linux_s390x.go:889:2: PR_CAP_AMBIENT redeclared in this block)))))
vet: import failed: type-checking package "net/http" failed (/Users/gri/go/src/net/http/client.go:13:2: could not import crypto/tls (type-checking package "crypto/tls" failed (/Users/gri/go/src/crypto/tls/cipher_suites.go:15:2: could not import crypto/x509 (type-checking package "crypto/x509" failed (/Users/gri/go/src/crypto/x509/pem_decrypt.go:16:2: could not import encoding/hex (type-checking package "encoding/hex" failed (/Users/gri/go/src/encoding/hex/hex.go:11:2: could not import fmt (type-checking package "fmt" failed (/Users/gri/go/src/fmt/print.go:10:2: could not import os (type-checking package "os" failed (/Users/gri/go/src/os/dir_unix.go:12:2: could not import syscall (type-checking package "syscall" failed (/Users/gri/go/src/syscall/zerrors_linux_s390x.go:889:2: PR_CAP_AMBIENT redeclared in this block)))))))))))))
vet: import failed: type-checking package "net/http" failed (/Users/gri/go/src/net/http/client.go:13:2: could not import crypto/tls (type-checking package "crypto/tls" failed (/Users/gri/go/src/crypto/tls/cipher_suites.go:15:2: could not import crypto/x509 (type-checking package "crypto/x509" failed (/Users/gri/go/src/crypto/x509/pem_decrypt.go:16:2: could not import encoding/hex (type-checking package "encoding/hex" failed (/Users/gri/go/src/encoding/hex/hex.go:11:2: could not import fmt (type-checking package "fmt" failed (/Users/gri/go/src/fmt/print.go:10:2: could not import os (type-checking package "os" failed (/Users/gri/go/src/os/dir_unix.go:12:2: could not import syscall (type-checking package "syscall" failed (/Users/gri/go/src/syscall/zerrors_linux_s390x.go:889:2: PR_CAP_AMBIENT redeclared in this block)))))))))))))
PANIC archive/zip/reader_test.go:372:17: time.Parse (kind = 1)
panic: archive/zip/reader_test.go:372:17: &{time Parse} (kind = 1)
 [recovered]
	panic: archive/zip/reader_test.go:372:17: &{time Parse} (kind = 1)


goroutine 1 [running]:
go/types.(*Checker).handleBailout(0xc4200fe540, 0xc42133d580)
	/Users/gri/go/src/go/types/check.go:225 +0xa4
panic(0x1274a20, 0xc420bb8080)
	/Users/gri/go/src/runtime/panic.go:491 +0x283
go/types.(*Checker).rawExpr(0xc4200fe540, 0xc4207238c0, 0x1418be0, 0xc4201e69a0, 0x0, 0x0, 0xc42133afa0)
	/Users/gri/go/src/go/types/expr.go:978 +0x6dd
go/types.(*Checker).exprOrType(0xc4200fe540, 0xc4207238c0, 0x1418be0, 0xc4201e69a0)
	/Users/gri/go/src/go/types/expr.go:1576 +0x5f
go/types.(*Checker).call(0xc4200fe540, 0xc4207238c0, 0xc4201e4840, 0x0)
	/Users/gri/go/src/go/types/call.go:15 +0x66
go/types.(*Checker).exprInternal(0xc4200fe540, 0xc4207238c0, 0x14184a0, 0xc4201e4840, 0x0, 0x0, 0xc42133b6d0)
	/Users/gri/go/src/go/types/expr.go:1427 +0x1d21
go/types.(*Checker).rawExpr(0xc4200fe540, 0xc4207238c0, 0x14184a0, 0xc4201e4840, 0x0, 0x0, 0x0)
	/Users/gri/go/src/go/types/expr.go:959 +0x84
go/types.(*Checker).multiExpr(0xc4200fe540, 0xc4207238c0, 0x14184a0, 0xc4201e4840)
	/Users/gri/go/src/go/types/expr.go:1533 +0x62
go/types.(*Checker).initVars.func1(0xc4207238c0, 0x0)
	/Users/gri/go/src/go/types/assignments.go:206 +0x5d
go/types.unpack(0xc42133ba00, 0x1, 0x1, 0x1076c84, 0xc420193c9a, 0x0)
	/Users/gri/go/src/go/types/call.go:140 +0x6a
go/types.(*Checker).initVars(0xc4200fe540, 0xc420bb8040, 0x2, 0x2, 0xc4201e29d0, 0x1, 0x1, 0x0)
	/Users/gri/go/src/go/types/assignments.go:206 +0xf9
go/types.(*Checker).shortVarDecl(0xc4200fe540, 0xb77f, 0xc4201e6940, 0x2, 0x2, 0xc4201e29d0, 0x1, 0x1)
	/Users/gri/go/src/go/types/assignments.go:316 +0x878
go/types.(*Checker).stmt(0xc4200fe540, 0x0, 0x14182a0, 0xc4201e4880)
	/Users/gri/go/src/go/types/stmt.go:391 +0x3763
go/types.(*Checker).stmtList(0xc4200fe540, 0x0, 0xc4201e4ac0, 0x3, 0x4)
	/Users/gri/go/src/go/types/stmt.go:110 +0x88
go/types.(*Checker).stmt(0xc4200fe540, 0x0, 0x1418420, 0xc4201e84b0)
	/Users/gri/go/src/go/types/stmt.go:477 +0x4041
go/types.(*Checker).stmt(0xc4200fe540, 0x0, 0x14188e0, 0xc4201e4b00)
	/Users/gri/go/src/go/types/stmt.go:489 +0x424a
go/types.(*Checker).stmtList(0xc4200fe540, 0x0, 0xc4201de200, 0x12, 0x20)
	/Users/gri/go/src/go/types/stmt.go:110 +0x88
go/types.(*Checker).funcBody(0xc4200fe540, 0xc421cb6cc0, 0xc420193c30, 0xc, 0xc420a2ce40, 0xc4201e8ff0)
	/Users/gri/go/src/go/types/stmt.go:42 +0x18d
go/types.(*Checker).functionBodies(0xc4200fe540)
	/Users/gri/go/src/go/types/resolver.go:476 +0xdb
go/types.(*Checker).checkFiles(0xc4200fe540, 0xc42020ac80, 0x7, 0x8, 0x0, 0x0)
	/Users/gri/go/src/go/types/check.go:241 +0xcb
go/types.(*Checker).Files(0xc4200fe540, 0xc42020ac80, 0x7, 0x8, 0xc420dc54d0, 0x0)
	/Users/gri/go/src/go/types/check.go:230 +0x49
go/types.(*Config).Check(0xc421158580, 0xc42008cbd0, 0x3, 0xc42008f4c0, 0xc42020ac80, 0x7, 0x8, 0xc4205371d0, 0x111e70d, 0x12b89e0, ...)
	/Users/gri/go/src/go/types/api.go:351 +0x1b3
main.(*Package).check(0xc420272600, 0xc42008f4c0, 0xc42020ac80, 0x7, 0x8, 0x0, 0xc420288580)
	/Users/gri/go/src/cmd/vet/types.go:93 +0x37d
main.doPackage(0x7fff5fbffb51, 0xb, 0xc4200a8b80, 0x7, 0x8, 0x0, 0x0)
	/Users/gri/go/src/cmd/vet/main.go:351 +0x919
main.doPackageDir(0x7fff5fbffb51, 0xb)
	/Users/gri/go/src/cmd/vet/main.go:293 +0x586
main.visit(0x7fff5fbffb51, 0xb, 0x1419de0, 0xc4200856c0, 0x0, 0x0, 0x0, 0x0)
	/Users/gri/go/src/cmd/vet/main.go:386 +0xe6
path/filepath.walk(0x7fff5fbffb51, 0xb, 0x1419de0, 0xc4200856c0, 0x12e4c20, 0x0, 0xc420045e70)
	/Users/gri/go/src/path/filepath/path.go:356 +0x81
path/filepath.Walk(0x7fff5fbffb51, 0xb, 0x12e4c20, 0xc, 0xc4200855f0)
	/Users/gri/go/src/path/filepath/path.go:403 +0x11d
main.walkDir(0x7fff5fbffb51, 0xb)
	/Users/gri/go/src/cmd/vet/main.go:401 +0x41
main.main()
	/Users/gri/go/src/cmd/vet/main.go:249 +0x3c2
@griesemer griesemer added this to the Go1.9Maybe milestone Jun 28, 2017
@griesemer griesemer self-assigned this Jun 28, 2017
@griesemer
Copy link
Contributor Author

@griesemer griesemer commented Jun 28, 2017

Simpler reproducer:

  1. Apply the following patch (basically, add an type-check error to the syscall package):
diff --git a/src/syscall/exec_linux.go b/src/syscall/exec_linux.go
index 5cbabf7896..0104023356 100644
--- a/src/syscall/exec_linux.go
+++ b/src/syscall/exec_linux.go
@@ -11,6 +11,9 @@ import (
        "unsafe"
 )
 
+const foo = 0
+const foo = 0
+
 // SysProcIDMap holds Container ID to Host ID mappings used for User Namespaces in Linux.
 // See user_namespaces(7).
 type SysProcIDMap struct {
  1. Run GOOS=linux go tool vet -source $GOROOT/src/io

Loading

@bradfitz
Copy link
Contributor

@bradfitz bradfitz commented Jun 28, 2017

Now that we know how to work around this for Go 1.9 for the vetall builder (it was finding a real bug, but crashing instead of reporting it), I'm moving this to Go 1.10.

But feel free to fix sooner if it's easy.

Loading

@bradfitz bradfitz added this to the Go1.10 milestone Jun 28, 2017
@bradfitz bradfitz removed this from the Go1.9Maybe milestone Jun 28, 2017
@griesemer
Copy link
Contributor Author

@griesemer griesemer commented Jun 28, 2017

There's a trivial fix, but it's perhaps too aggressive: The problem is that the vet is using a source importer with go/types (it has to). The source importer fails to import the syscall package because it has a bug, yet go/type continues to use that partially type-checked syscall package (to be able to do some type-checking, per #16088 as requested by @alandonovan). The simple solution is to not use an incomplete package, and then the crash disappears. Still checking if there's a softer approach.

Loading

@gopherbot
Copy link

@gopherbot gopherbot commented Jun 28, 2017

CL https://golang.org/cl/47074 mentions this issue.

Loading

@griesemer
Copy link
Contributor Author

@griesemer griesemer commented Jun 28, 2017

See also #16088 .

Loading

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants