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: incorrect type inference #42920

Open
benjaminjkraft opened this issue Dec 1, 2020 · 1 comment
Open

cmd/go2go: incorrect type inference #42920

benjaminjkraft opened this issue Dec 1, 2020 · 1 comment
Assignees
Milestone

Comments

@benjaminjkraft
Copy link

@benjaminjkraft benjaminjkraft commented Dec 1, 2020

Consider the following code:

package main

func Map[T, U any](f func(T) (U, error), xs []T) ([]U, error) { return nil, nil }

func Apply(s string) func(func(string) (string, error)) (string, error) {
	return func(f func(string) (string, error)) (string, error) {
		return f(s)
	}
}

func main() {
	var input string
	var fs [](func(string) (string, error))
	Map[func(string) (string, error), string](Apply(input), fs) // works
	Map(Apply(input), fs)                                       // works, fails if previous line is removed
}

If we write out the types for Map(Apply(input), fs) everything works. If we write them out on the first line, and then omit them on the second, it works. But if we just omit them, the compiler returns errors (below) from the translated code; it seems to somehow be inferring func(string) string instead of func(string) (string, error) or something.

Sample errors:

./prog.go2:13: cannot use Apply(input) (type func(func(string) (string, error)) (string, error)) as type func(func(string) string) (string, error) in argument to instantiate୦୦Map୦func୮8string୮9୮0୮8string୮3୮0error୮9୦string
./prog.go2:13: cannot use fs (type []func(string) (string, error)) as type []func(string) string in argument to instantiate୦୦Map୦func୮8string୮9୮0୮8string୮3୮0error୮9୦string

Playground link: https://go2goplay.golang.org/p/J-5HQfAPIwM

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Dec 2, 2020

@ianlancetaylor ianlancetaylor added this to the Unreleased milestone Dec 2, 2020
@griesemer griesemer self-assigned this Dec 2, 2020
@griesemer griesemer modified the milestones: Unreleased, Go1.17 Dec 2, 2020
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.