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: Wrong line number on "ambiguous selector" message #53420

Closed
phemmer opened this issue Jun 17, 2022 · 2 comments
Closed

cmd/compile: Wrong line number on "ambiguous selector" message #53420

phemmer opened this issue Jun 17, 2022 · 2 comments
Labels
NeedsInvestigation
Milestone

Comments

@phemmer
Copy link

@phemmer phemmer commented Jun 17, 2022

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

$ go version
go version go1.18.3 linux/amd64

Does this issue reproduce with the latest release?

yes

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

go env Output
$ go env
GOARCH="amd64"
GOOS="linux"

What did you do?

package main

import "fmt"

type Foo struct{}
type Bar struct{}
type Both struct {
	Foo
	Bar
}

func (f Foo) Get() Foo   { return f }
func (b Bar) Get() Bar   { return b }
func (b Both) Get() Both { return b }

type Getter[T any] interface {
	Get() T
}

func Get[T Getter[T]](v T) T {
	r := v.Get()
	fmt.Println(r)
	return r
}

func main() {
	fmt.Println(Get(Both{}))
}

https://go.dev/play/p/0gpMl406d1K

What did you expect to see?

./prog.go:21:_: ambiguous selector v.Get

What did you see instead?

./prog.go:23:2: ambiguous selector v.Get

Line 23 is the return statement. Line 21 is the Get.

It would also be useful if the message indicated which type was ambiguous (in this case, it's the Both type).

Note there should be no error at all. But that is filed as issue #53419

@cagedmantis cagedmantis added the NeedsInvestigation label Jun 24, 2022
@cagedmantis cagedmantis added this to the Backlog milestone Jun 24, 2022
@cagedmantis
Copy link
Contributor

@cagedmantis cagedmantis commented Jun 24, 2022

/cc @randall77 @griesemer

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jun 24, 2022

Simplified reproducer:

package p

type A struct{}
type B struct{}
type AB struct {
	A
	B
}

func (A) m()  {}
func (B) m()  {}
func (AB) m() {}

func m[P interface{ m() }](v P) {
	v.m()
}

func _() {
	m(AB{})
}

which looks exactly like the simplified reproducer in #53419.

Closing as duplicate of #53419.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
NeedsInvestigation
Projects
None yet
Development

No branches or pull requests

3 participants