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/go2go: generic function type assignment fails to type check correctly #40060

Open
rogpeppe opened this issue Jul 5, 2020 · 3 comments
Open

cmd/go2go: generic function type assignment fails to type check correctly #40060

rogpeppe opened this issue Jul 5, 2020 · 3 comments
Assignees
Milestone

Comments

@rogpeppe
Copy link
Contributor

@rogpeppe rogpeppe commented Jul 5, 2020

commit 34f7622

The following program seems like it should compile OK, but it does not:

package main

func main() {
}

type S1(type T) struct {
	x S2(T)
}

type S2(type T) struct {
	y sfunc(T)
}

type sfunc(type T) func(*S1(T))

func (*S1(T)) a() {}

func (i *S1(T)) b(f sfunc(T)) {
	i.x.y = f
}

It produces the error:

prog.go2:19:10: cannot use f (variable of type sfunc(T)) as sfunc(T) value in assignment
@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jul 6, 2020

This looks like a bug in the type checker.

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jul 7, 2020

One of the functions is not properly instantiated; definitively a type-checker issue.

@rogpeppe
Copy link
Contributor Author

@rogpeppe rogpeppe commented Jul 7, 2020

Note that it works OK if the apparently unrelated method a is removed, which is odd.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants
You can’t perform that action at this time.