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: confusing error message for not implementing a pointer to an interface #64838

Open
cherrymui opened this issue Dec 21, 2023 · 1 comment
Labels
compiler/runtime Issues related to the Go compiler and/or runtime. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@cherrymui
Copy link
Member

cherrymui commented Dec 21, 2023

Go version

go1.21.4 (playground). Also any version since Go 1.18.

What operating system and processor architecture are you using (go env)?

N/A

What did you do?

https://go.dev/play/p/_OT3OvSlSeg

package main

type I interface{}
type T struct{ X *I }

var i I
var t = T{i}

func main() {}

Compile this code.

What did you expect to see?

./i.go:7:11: cannot use i (type I) as type *I in field value:
	*I is pointer to interface, not interface

This is what Go 1.17 and before emit.

What did you see instead?

./i.go:7:11: cannot use i (variable of type I) as *I value in struct literal: I does not implement *I (type *I is pointer to interface, not interface)

Specifically, it contains I does not implement *I. In the spec "implements" is only used for implementing an interface or a type constraint. There is no "implementing a pointer to an interface". So this does not implement *I is confusing. We probably want to remove it.

@gopherbot gopherbot added the compiler/runtime Issues related to the Go compiler and/or runtime. label Dec 21, 2023
@cherrymui cherrymui changed the title cmd/compile: confusing error message for cmd/compile: confusing error message for implementing a pointer to an interface Dec 21, 2023
@cherrymui cherrymui changed the title cmd/compile: confusing error message for implementing a pointer to an interface cmd/compile: confusing error message for not implementing a pointer to an interface Dec 21, 2023
@gopherbot
Copy link

Change https://go.dev/cl/552475 mentions this issue: cmd/compile/internal/types2, go/types: eliminate confusing error message

@dr2chase dr2chase added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Dec 28, 2023
@mknyszek mknyszek added this to the Backlog milestone Jan 3, 2024
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. NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
Status: In Progress
Development

Successfully merging a pull request may close this issue.

4 participants