Skip to content

cmd/compile: confusing error message for not implementing a pointer to an interface #64838

Description

@cherrymui

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    NeedsInvestigationSomeone must examine and confirm this is a valid issue and not a duplicate of an existing one.compiler/runtimeIssues related to the Go compiler and/or runtime.

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions