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

go/types: named types defined within a function print as if defined at package scope #5501

Open
adonovan opened this issue May 17, 2013 · 6 comments
Milestone

Comments

@adonovan
Copy link
Member

package main
type T int
func f() {
        type T int
}

Both of these types are printed as "main.T".  This is ambiguous and confusing;
the f-local type should have a different name.  Not sure what 6g does.
@rsc
Copy link
Contributor

rsc commented Nov 27, 2013

Comment 2:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 3:

Labels changed: added release-none, removed go1.3maybe.

@rsc
Copy link
Contributor

rsc commented Dec 4, 2013

Comment 4:

Labels changed: added repo-tools.

@adonovan
Copy link
Member Author

Comment 5:

Here's a concrete suggestion: the local type should have name that is not a valid Go
identifier, e.g. main.T$1, where 1 is a sequence number for fresh identifiers.
For the record: gc and go/types behave the same:
% cat ~/5501.go 
package main
import "fmt"
type T int
var outer T
func main() {
    type T int
    var inner T
    fmt.Printf("%T %T\n", outer, inner)
}
% go run ~/5501.go 
main.T main.T
% ./ssadump -run ~/5501.go 
main.T main.T

@rsc rsc added this to the Unplanned milestone Apr 10, 2015
@rsc rsc changed the title go.tools/go/types: named types defined within a function print as if defined at package scope x/tools/go/types: named types defined within a function print as if defined at package scope Apr 14, 2015
@rsc rsc modified the milestones: Unreleased, Unplanned Apr 14, 2015
@rsc rsc removed the repo-tools label Apr 14, 2015
@griesemer griesemer changed the title x/tools/go/types: named types defined within a function print as if defined at package scope go/types: named types defined within a function print as if defined at package scope Jul 31, 2015
@griesemer
Copy link
Contributor

This shouldn't be too hard to address. Try for 1.9.

@griesemer griesemer modified the milestones: Go1.9, Unreleased Feb 25, 2017
@griesemer
Copy link
Contributor

Better suggestion than #5501 (comment):

Print a type together with position information; that will remove any ambiguity. This can be optimized such that the position information is only present if there two types with the same name in the same package.

Shouldn't be too hard to do but may affect tests that rely on a specific output format. Thus moving to Go1.10.

@griesemer griesemer modified the milestones: Go1.10, Go1.9 Jun 23, 2017
@rsc rsc modified the milestones: Go1.10, Go1.11 Nov 22, 2017
@griesemer griesemer modified the milestones: Go1.11, Unplanned Jun 6, 2018
@odeke-em odeke-em self-assigned this Jun 6, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants