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
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Milestone

Comments

@phemmer
Copy link

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 Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 24, 2022
@cagedmantis cagedmantis added this to the Backlog milestone Jun 24, 2022
@cagedmantis
Copy link
Contributor

/cc @randall77 @griesemer

@griesemer
Copy link
Contributor

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.

@golang golang locked and limited conversation to collaborators Jun 24, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

4 participants