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
Assignees
Milestone

Comments

@adonovan
Copy link

@adonovan adonovan commented May 17, 2013

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 rsc commented Nov 27, 2013

Comment 2:

Labels changed: added go1.3maybe.

@rsc
Copy link
Contributor

@rsc rsc commented Dec 4, 2013

Comment 3:

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

@rsc
Copy link
Contributor

@rsc rsc commented Dec 4, 2013

Comment 4:

Labels changed: added repo-tools.

@adonovan
Copy link
Author

@adonovan adonovan commented Feb 18, 2014

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 added this to the Unreleased milestone Apr 14, 2015
@rsc rsc removed this from the Unplanned milestone 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

@griesemer griesemer commented Feb 25, 2017

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

@griesemer griesemer added this to the Go1.9 milestone Feb 25, 2017
@griesemer griesemer removed this from the Unreleased milestone Feb 25, 2017
@griesemer
Copy link
Contributor

@griesemer griesemer commented Jun 23, 2017

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 added this to the Go1.10 milestone Jun 23, 2017
@griesemer griesemer removed this from the Go1.9 milestone Jun 23, 2017
@rsc rsc removed this from the Go1.10 milestone Nov 22, 2017
@rsc rsc added this to the Go1.11 milestone Nov 22, 2017
@griesemer griesemer removed this from the Go1.11 milestone Jun 6, 2018
@griesemer griesemer added this to the Unplanned milestone 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
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants