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

Comments

Projects
None yet
3 participants
@adonovan
Copy link

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

This comment has been minimized.

Copy link
Contributor

commented Nov 27, 2013

Comment 2:

Labels changed: added go1.3maybe.

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 3:

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

@rsc

This comment has been minimized.

Copy link
Contributor

commented Dec 4, 2013

Comment 4:

Labels changed: added repo-tools.

@adonovan

This comment has been minimized.

Copy link
Author

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 removed release-none labels 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

This comment has been minimized.

Copy link
Contributor

commented Feb 25, 2017

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

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

@griesemer

This comment has been minimized.

Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.