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

cmd/vet: internal error: no range for "n" #26725

Closed
dvyukov opened this issue Jul 31, 2018 · 7 comments

Comments

Projects
None yet
4 participants
@dvyukov
Copy link
Member

commented Jul 31, 2018

go version devel +ce06f5a222 Tue Jul 31 18:11:29 2018 +0000 linux/amd64
Checkout google/syzkaller@8ef497b

$ pkg/tool/linux_amd64/vet --shadow  $GOPATH/src/github.com/google/syzkaller/pkg/compiler
src/github.com/google/syzkaller/pkg/compiler/check.go:90: internal error: no range for "n"

dvyukov added a commit to google/syzkaller that referenced this issue Jul 31, 2018

pkg/compiler: work around vet crash
vetshadow not works, so enable it.

Update golang/go#26725
Update #538
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 31, 2018

Also happens with 1.10 so not a regression; setting milestone to 1.12.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 31, 2018

Simpler reproduction case:

package p

func F(x interface{}) int {
	switch v := x.(type) {
	case int, int32:
		if v, ok := x.(int); ok {
			return v
		}
	case int64:
		return int(v)
	}
	return 0
}
@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 31, 2018

The error has happened since 1.5, when vet was added to the Go release.

@ianlancetaylor

This comment has been minimized.

Copy link
Contributor

commented Jul 31, 2018

I think the bug is that for a variable defined in a type switch statement the go/types package returns it with a nil entry in Defs. In vet that turns into passing nil as the obj argument to growSpan, which seems meaningless. Oddly, though, looking up the identifier in the parent scope returns a non-nil types.Object, an Object that is not found elsewhere in Defs or Uses.

CC @griesemer

@griesemer griesemer self-assigned this Aug 6, 2018

@griesemer

This comment has been minimized.

Copy link
Contributor

commented Sep 13, 2018

@ianlancetaylor That object is introduced implicitly for each type switch case clause; it is found in the Implicits map.

@gopherbot

This comment has been minimized.

Copy link

commented Sep 13, 2018

Change https://golang.org/cl/135117 mentions this issue: cmd/vet: avoid internal error for implicitly declared type switch vars

gopherbot pushed a commit that referenced this issue Sep 13, 2018

cmd/vet: avoid internal error for implicitly declared type switch vars
For type switches using a short variable declaration of the form

   switch t := x.(type) {
   case T1:
   ...

go/types doesn't declare the symbolic variable (t in this example)
with the switch; thus such variables are not found in types.Info.Defs.

Instead they are implicitly declared with each type switch case,
and can be found in types.Info.Implicits.

Adjust the shadowing code accordingly.

Added a test case to verify that the issue is fixed, and a test
case verifying that the shadowing code now considers implicitly
declared variables introduces in type switch cases.

While at it, also fixed the (internal) error reporting to provide
more accurate information.

Fixe #26725.

Change-Id: If408ed9e692bf47c640f81de8f46bf5eb43415b0
Reviewed-on: https://go-review.googlesource.com/135117
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Daniel Martí <mvdan@mvdan.cc>
Reviewed-by: Alan Donovan <adonovan@google.com>
@griesemer

This comment has been minimized.

Copy link
Contributor

commented Sep 17, 2018

This was fixed by https://golang.org/cl/135117, but the respective commit message contained a typo in the "Fixes ..." line and thus didn't auto-close this issue. Closing now.

@griesemer griesemer closed this Sep 17, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.