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

Comments

@TapirLiu
Copy link
Contributor

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

sorry, wrong code posted. Corrected now.

@griesemer
Copy link
Contributor

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

@griesemer griesemer added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 19, 2020
@griesemer griesemer added this to the Unreleased milestone Jun 19, 2020
@ianlancetaylor
Copy link
Contributor

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

Are local types instantiated at runtime?

@TapirLiu
Copy link
Contributor Author

BTW, is this a temporary limit?

@ianlancetaylor
Copy link
Contributor

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.

@golang golang locked and limited conversation to collaborators Jun 20, 2021
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