Skip to content

go/types: review/document AssignableTo code path for untyped value types #32146

@muirdm

Description

@muirdm

What version of Go are you using (go version)?

$ go version
go version go1.12.1 darwin/amd64

Does this issue reproduce with the latest release?

Yes.

What operating system and processor architecture are you using (go env)?

go env Output
$ go env
GOARCH="amd64"
GOHOSTARCH="amd64"
GOHOSTOS="darwin"
GOOS="darwin"

What did you do?

I called types.AssignableTo to see if an untyped int constant was assignable to a named int type.

https://play.golang.org/p/Xq33qWpFsy5

What did you expect to see?

I expected it to be assignable.

What did you see instead?

It was reported as not assignable.

At first I thought it was due to an implicit type conversion and they weren't technically assignable, but in the spec assignability seems to include implicit conversions, at least for non-constant values. For untyped constants in particular it says an untyped constant x is assignable to type T if x is in the set of values determined by T.. I'm not sure exactly what that means or if it disqualifies this case. In general since the untyped constant is assignable to the named type, I assumed the AssignableTo function would agree.

Also note that reflect.Type.AssignableTo behaves consistently with types.AssignableTo.

/cc @griesemer since you are primary owner of go/types

Metadata

Metadata

Assignees

No one assigned

    Labels

    DocumentationIssues describing a change to documentation.NeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions