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: error message refers to aliased type instead of the alias type name #67628

Closed
griesemer opened this issue May 24, 2024 · 5 comments
Assignees
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Milestone

Comments

@griesemer
Copy link
Contributor

package p

func f[P any](x P) P { return x }

func _() {
	type A = int
	var a A
	b := f(a) // type of B is A
	_ = b + "foo"
}

produces

...: invalid operation: b + "foo" (mismatched types int and untyped string)

It should say:

mismatched types A and untyped string

cc: @findleyr

@griesemer griesemer added the NeedsFix The path to resolution is known, but the work has not been done. label May 24, 2024
@griesemer griesemer added this to the Go1.23 milestone May 24, 2024
@griesemer griesemer self-assigned this May 24, 2024
@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label May 24, 2024
@griesemer
Copy link
Contributor Author

Related to #67547.

@findleyr
Copy link
Member

Presumably this is because the inference algorithm strips alias information. I would expect that the type of b is int, not A.
This may be difficult to fix.

@griesemer
Copy link
Contributor Author

I would expect that the type of b is int, not A.

That's what the error message says. But I think it should say A. Not sure why you say it should be int.

@gopherbot
Copy link
Contributor

Change https://go.dev/cl/588797 mentions this issue: go/types, types2: don't lose alias information during unification

@findleyr
Copy link
Member

I would expect that the type of b is int, not A.

That's what the error message says. But I think it should say A. Not sure why you say it should be int.

I merely meant that the type is int, not that it should be int. In other words, the problem is inference, not the error message.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsFix The path to resolution is known, but the work has not been done.
Projects
None yet
Development

No branches or pull requests

3 participants