Skip to content

cmd/compile: incorrect error message when assigning an interface to a constant #24755

@mundaym

Description

@mundaym

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

go version devel +68c7cb25a7 Wed Apr 4 12:18:29 2018 +0100 darwin/amd64

Does this issue reproduce with the latest release?

Yes (go version go1.10.1 darwin/amd64).

What did you do?

Compiled https://play.golang.org/p/jzbFN6k7Jhk

What did you expect to see?

./const.go:10:7: const initializer I((*T)(nil)) is not a constant

What did you see instead?

./const.go:10:12: cannot convert (*T)(nil) (type *T) to type I:
	*T does not implement I (missing F method)

*T does implement I so this error message is wrong. The real issue is that the RHS is not a valid constant.

Note that the correct error message is shown if the declaration of F() is moved to be above the assertion in the file (i.e. https://play.golang.org/p/9f2SQfBfteA). If the const is changed to var then the program compiles correctly regardless of where F is declared.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.compiler/runtimeIssues related to the Go compiler and/or runtime.early-in-cycleA change that should be done early in the 3 month dev cycle.

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions