Skip to content

cmd/compile: suboptimal error for &T{} literal mismatch #26855

Closed
@dsymonds

Description

@dsymonds

Does this issue reproduce with the latest release?

In the playground, yes.

What did you do?

https://play.golang.org/p/uQjX9qTwBz1

package main

type S struct {
	Name T
}

type T struct {
	First string
}

func main() {
	_ = &S{
		Name: &T{First: "Rob"},
	}
}

What did you expect to see?

An error message pointing out the T vs. *T type problem.

What did you see instead?

prog.go:13:7: cannot use T literal (type *T) as type T in field value

The error message is there, but it is phrased oddly. cannot use T literal is confusing. I'm using a &T literal. If you put aside the parenthetical for a moment, the oddness is apparent: cannot use T literal as type T in field value. I think this error message could be improved.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FrozenDueToAgeNeedsFixThe path to resolution is known, but the work has not been done.

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions