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/compile: use of untyped nil in switch #11668

Closed
dvyukov opened this issue Jul 11, 2015 · 9 comments
Closed

cmd/compile: use of untyped nil in switch #11668

dvyukov opened this issue Jul 11, 2015 · 9 comments
Milestone

Comments

@dvyukov
Copy link
Member

dvyukov commented Jul 11, 2015

gc fails on the following program:

package a
func f() {
    switch nil {
    }
}
go.go:4: use of untyped nil

The program is correct and must be compiled without errors.

go version devel +9b04852 Sat Jul 11 00:08:50 2015 +0000 linux/amd64

@dvyukov
Copy link
Member Author

dvyukov commented Jul 11, 2015

@griesemer to judge compiler disagreement

@mdempsky
Copy link
Member

As far as I can tell, the spec doesn't say what should happen if the switch expression is untyped. E.g., switch nil {} above or something like switch 42 { case byte(42): } or type Bool bool; switch { case Bool(true): }.

cmd/compile seems to apply the implicit typing logic from section "Variable declarations" (i.e., use the default type for untyped constants, and reject untyped nil).

@griesemer
Copy link
Contributor

@mdempsky is correct. That said, we know that the spec is underspecified when it comes to the switch statement. I believe that nil could be permitted, but I am not feeling strongly about it. I think we need to nail down the spec issue first.

@dvyukov
Copy link
Member Author

dvyukov commented Jul 11, 2015

A similar case:

func f() {
    switch 1<<100 {
    }
}

gotype compiles without errors, gc says constant 1267650600228229401496703205376 overflows int.

@griesemer
Copy link
Contributor

This is related to #6398.

@ianlancetaylor ianlancetaylor added this to the Go1.6 milestone Jul 11, 2015
@ianlancetaylor ianlancetaylor assigned griesemer and unassigned rsc Jul 11, 2015
@gopherbot
Copy link

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

@griesemer
Copy link
Contributor

Per https://golang.org/cl/12711 this program is incorrect and gc correctly reports an error.

@mikioh mikioh modified the milestones: Go1.5, Go1.6 Jul 31, 2015
@dvyukov
Copy link
Member Author

dvyukov commented Jul 31, 2015

@griesemer should we file a bug on go/types?

@griesemer
Copy link
Contributor

@dvyukov this is already fixed in https://go-review.googlesource.com/#/c/12713/ (for 1.6)

@golang golang locked and limited conversation to collaborators Aug 5, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

7 participants