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: poor error for constant using missing import #26818

Open
dsymonds opened this Issue Aug 5, 2018 · 1 comment

Comments

Projects
None yet
4 participants
@dsymonds
Member

dsymonds commented Aug 5, 2018

Please answer these questions before submitting your issue. Thanks!

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

Playground.

Does this issue reproduce with the latest release?

I haven't checked, but the playground says it is running Go 1.10.3.

What did you do?

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

package main

import (
	"fmt"
)

func main() {
	const delay = 5 * time.Second
	fmt.Println(delay)
}

What did you expect to see?

One error, pointing out that I didn't import "time".

What did you see instead?

Two errors, one of which is misleading:

prog.go:8:8: const initializer 5 * time.Second is not a constant
prog.go:8:20: undefined: time

The first error is outright wrong if the "time" package was imported, yet it was printed, and worse, it came first. The only useful error there is the second message.

@FiloSottile FiloSottile added this to the Go1.12 milestone Aug 6, 2018

@odeke-em

This comment has been minimized.

Member

odeke-em commented Oct 18, 2018

Thank you for reporting this @dsymonds!

I'll kindly /cc @griesemer too

@odeke-em odeke-em self-assigned this Oct 18, 2018

@griesemer griesemer modified the milestones: Go1.12, Go1.13 Dec 11, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment