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: compile or not depending on whether or not a type is local or global declared #39686

Closed
TapirLiu opened this issue Jun 18, 2020 · 6 comments
Assignees
Milestone

Comments

@TapirLiu
Copy link
Contributor

@TapirLiu TapirLiu commented Jun 18, 2020

Playground code:

package main

type Int interface {
    type int
}

func Foo(type T Int) ([]T) {} // compilation error: undefined: MyInt


func main() {
    type MyInt int // If the type is declared outside, then then program compiles okay
    Foo([]MyInt(nil))
}
@TapirLiu
Copy link
Contributor Author

@TapirLiu TapirLiu commented Jun 18, 2020

sorry, wrong code posted. Corrected now.

@griesemer
Copy link
Contributor

@griesemer griesemer commented Jun 19, 2020

This is a problem with the translator. It type-checks fine.

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 20, 2020

This is a documented shortcoming of the translation tool. As go doc cmd/go2go reports:

Because this tool generates Go files, and because instantiated types and functions need to refer to the types with which they are instantiated, using function-local types as type arguments is not supported.

@TapirLiu
Copy link
Contributor Author

@TapirLiu TapirLiu commented Jun 20, 2020

Are local types instantiated at runtime?

@TapirLiu
Copy link
Contributor Author

@TapirLiu TapirLiu commented Jun 20, 2020

BTW, is this a temporary limit?

@ianlancetaylor
Copy link
Contributor

@ianlancetaylor ianlancetaylor commented Jun 20, 2020

This is a limitation of the translation tool. It will not be fixed in the translation tool. The translation tool is a temporary program designed to let people experiment with generics as described in the current design draft.

This is not a limitation of the language change described in the design draft. If the design draft becomes a language change proposal, and if the language change proposal is adopted, then the implementation in the Go compiler will not have this limitation.

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.