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: "const _ string = 1" error message says integers can't be converted to strings #22070

Open
mdempsky opened this Issue Sep 27, 2017 · 4 comments

Comments

Projects
None yet
4 participants
@mdempsky
Member

mdempsky commented Sep 27, 2017

Compiling this package with cmd/compile (or go/types) produces an error message that 1 cannot be "converted" to type string. In fact it can be converted, it just can't be assigned, which is the criteria required here by the language spec.

package p
const _ string = 1

/cc @griesemer

@go101

This comment has been minimized.

go101 commented Sep 28, 2017

The accurate message should be cannot implicitly convert 1 to type string.

There are many error messages are not very accurate. Another example:

type T *int
type S struct {
	T // error: embedded type cannot be a pointer
}

The accurate message should be embedded type cannot be a defined pointer

@mdempsky

This comment has been minimized.

Member

mdempsky commented Sep 28, 2017

I think the correct wording is cannot assign 1 to type string. The only time the spec talks about "implicit conversions" is in the context of default type for untyped constants, which does not apply here.

The embedded type error message reads fine to me as is. T is still a pointer type.

@go101

This comment has been minimized.

go101 commented Sep 29, 2017

Yes, T is a pointer, that is why the message is not accurate.
In fact, embedded type can be a pointer.
It is just that embedded type cannot be a defined pointer.

type T *int
type S struct {
	T // error: embedded type cannot be a pointer
}
type S struct {
	*int // ok. 
}

@ianlancetaylor ianlancetaylor added this to the Go1.11 milestone Mar 29, 2018

@griesemer

This comment has been minimized.

Contributor

griesemer commented May 31, 2018

The error message is inaccurate, but we do get an error message. Not urgent.

@griesemer griesemer modified the milestones: Go1.11, Unplanned May 31, 2018

@griesemer griesemer self-assigned this May 31, 2018

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