Skip to content
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: misleading error message when using type parameter in typeset #50420

Open
icholy opened this issue Jan 4, 2022 · 7 comments
Open

cmd/compile: misleading error message when using type parameter in typeset #50420

icholy opened this issue Jan 4, 2022 · 7 comments
Assignees
Milestone

Comments

@icholy
Copy link

@icholy icholy commented Jan 4, 2022

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

devel go1.18-c8861432b8 Sun Jan 2 14:27:43 2022 +0000

What did you do?

type X[T any] interface {
	T | string
}

https://go.dev/play/p/v-8zaOs_d3r?v=gotip

What did you expect to see?

"cannot use type parameter in typeset"

What did you see instead?

"cannot embed a type parameter"

@go101
Copy link

@go101 go101 commented Jan 4, 2022

This is specified in https://tip.golang.org/ref/spec#Interface_types

In a union, a term cannot be a type parameter ...

[edit], Aha, you mean the message is not clear. Okay, it is some of.

@thanm
Copy link
Contributor

@thanm thanm commented Jan 4, 2022

@griesemer per owners.

Personally I think "cannot use type parameter in typeset" is perfectly clear as it is.

@griesemer griesemer added this to the Backlog milestone Jan 4, 2022
@griesemer griesemer self-assigned this Jan 4, 2022
@griesemer
Copy link
Contributor

@griesemer griesemer commented Jan 4, 2022

Just to be clear (@thanm ), the current error message is: cannot embed a type parameter.
cc: @findleyr for suggestions.

@findleyr
Copy link
Contributor

@findleyr findleyr commented Jan 4, 2022

I'm not sure if the word(s) 'type set' (or typeset) are appropriate here, since it refers to the entire type set of the interface type. Maybe "cannot use a type parameter in a union", which is the phrasing currently used in the spec.

@findleyr
Copy link
Contributor

@findleyr findleyr commented Jan 4, 2022

...though it may also be confusing that *T is valid here, as in

type X[T any] interface {
	*T | string
}

Maybe union terms cannot be type parameters is sufficiently specific.

@go101
Copy link

@go101 go101 commented Jan 5, 2022

Some off-topic, should "union" be replaced with "intersection"? int | string means allowing the operations which are legal for both int and string, instead of for either int or string.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jan 5, 2022

int | string means that both int and string are in the type set of the interface. More generally T1 | T2 means that the union of the type sets of T1 and T2 are in the type set of the interface. So union is the correct term.

It's true that because an operation is supported if it is supported by all types in the type set, one can view operations as going by the intersection. But from a type set perspective it is definitely a union operator.

See #45346.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
6 participants