Description
Currently if you type check this code with go/types:
var (
_ int = 0
_ = int(0)
_ *int = nil
_ = (*int)(nil)
)
both 0
expressions will have type "int", whereas the first nil
expression will have type "untyped nil", and the second will have type "*int". This seems at the least inconsistent. See http://play.golang.org/p/cw8Ldz1U5D
My expectation was that the 0
s would type check as "untyped int" and the nil
s would type check as "untyped nil". The current behavior of rewriting the type of untyped expressions seems to have two negative consequences that I've noticed trying to use go/types:
- It makes it difficult to identify useless conversion operations; i.e., expressions
T(x)
wherex
is already of typeT
. Expressions likeint(0)
will trigger as false positives. - It causes
types.TypeAndValue.IsNil
to return false for thenil
subexpression in(*int)(nil)
, because it doesn't have the type "untyped nil" anymore.
It also seems inconsistent with conversions of already typed expressions, where they're not rewritten.
However, I notice api_test.go has a bunch of tests that seem to explicitly test for this behavior, so it seems intentional?
CC @griesemer