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: generic interface conversion failed, reporting types from different scopes. #52027

Closed
taoso opened this issue Mar 30, 2022 · 5 comments
Closed
Labels
NeedsInvestigation

Comments

@taoso
Copy link

@taoso taoso commented Mar 30, 2022

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

$ go version
go1.18

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

What did you do?

Run the following code at https://go.dev/play/p/IB1FUMuciDG

package main

type Foo[T any] interface {
	Hi()
}

type Bar struct{}

func (b Bar) Hi() {}

func hi[T any]() Foo[T] {
	return Bar{}
}

func main() {
	a := hi[int]()
	_ = a.(Bar)
}

What did you expect to see?

No panic.

What did you see instead?

panic: interface conversion: main.Foo[int] is main.Bar, not main.Bar (types from different scopes)

goroutine 1 [running]:
main.main()
	/tmp/sandbox248030288/prog.go:17 +0x2e

Program exited.
@cuonglm cuonglm changed the title Generic interface conversion failed, reporting types from different scopes. cmd/compile: generic interface conversion failed, reporting types from different scopes. Mar 30, 2022
@cuonglm cuonglm added the NeedsInvestigation label Mar 30, 2022
@taoso
Copy link
Author

@taoso taoso commented Mar 30, 2022

Duplicate with #52026

@taoso taoso closed this as completed Mar 30, 2022
@fractalqb
Copy link

@fractalqb fractalqb commented Jun 13, 2022

Could it be that this bug is back with 1.18.3? When I compile this code:

package main

import (
	"fmt"

	"github.com/fractalqb/change"
	"github.com/fractalqb/change/chgsql"
)

var id change.Val[uint64]

func main() {
	v := chgsql.Nullable[uint64](&id, 0)
	fmt.Println(v)
}

With 1.18.2 it runs and has output <nil>. Compiling it with 1.18.3 works but when I run it, I get:

panic: interface conversion: change.Changeable[go.shape.uint64_0] is *change.Val[uint64], not *change.Val[uint64] (types from different scopes)

goroutine 1 [running]:
github.com/fractalqb/change/chgsql.Nullable[...](...)
	.../src/github.com/fractalqb/change/chgsql/type.go:28
main.main()
	.../different-scopes/main.go:13 +0x2e

Even more strange: If I add a line to .../src/github.com/fractalqb/change/chgsql/type.go:

func Nullable[T comparable](v change.Changeable[T], null T) interface{} {
	fmt.Printf("T(v): %T", v) // this is the new line
	db := v.Get()
	if db == null {
		return nil
	}
	return db
}

I can compile and run with 1.18.3 and get as output: T(v): *change.Val[uint64]<nil> – No panic

@cuonglm
Copy link
Member

@cuonglm cuonglm commented Jun 13, 2022

It's strange that if I build release-branch.go1.18 at commit 4068be5 (HEAD commit of the branch), the problem occurs, but at commit 5a89bb3 (HEAD~1), it doesn't.

cc @dmitshur

Updated

Also fix at tip, so sounds like problem with git tagging 🤔

@dmitshur
Copy link
Contributor

@dmitshur dmitshur commented Jun 13, 2022

Since this issue is closed as a duplicate of #52026, and that issue is also closed, it's going to be harder to investigate here. If you're seeing a problem that looks related, please file a new issue and reference these two issues as needed.

@cuonglm The only change between those commits is the VERSION file. One possibility is that changing the Go version has effect on cache, so perhaps to investigate further you'll want to be sure to clear relevant Go caches (or use temporary directories for said caches).

@cuonglm
Copy link
Member

@cuonglm cuonglm commented Jun 13, 2022

@dmitshur Hmm, what I did:

$ go1.18.3 clean -cache -modcache
$ go1.18.3 run -a main.go
go: downloading github.com/fractalqb/change v0.4.1
panic: interface conversion: change.Changeable[go.shape.uint64_0] is *change.Val[uint64], not *change.Val[uint64] (types from different scopes)

goroutine 1 [running]:
github.com/fractalqb/change/chgsql.Nullable[...](...)
	/home/cuonglm/go/pkg/mod/github.com/fractalqb/change@v0.4.1/chgsql/type.go:27
main.main()
	/home/cuonglm/tt/main.go:13 +0x2e
exit status 2

Same problem happens if I build go from source on branch release-branch.go1.18

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

4 participants