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/compile: aliases should not apply to unnamed types #18893

Closed
davecheney opened this issue Feb 2, 2017 · 1 comment
Closed

cmd/compile: aliases should not apply to unnamed types #18893

davecheney opened this issue Feb 2, 2017 · 1 comment

Comments

@davecheney
Copy link
Contributor

davecheney commented Feb 2, 2017

Please answer these questions before submitting your issue. Thanks!

What version of Go are you using (go version)?

go version devel +08a3a7c Thu Feb 2 02:14:50 2017 +0000 linux/amd64

What operating system and processor architecture are you using (go env)?

linux/amd64

What did you do?

package main

import (
        "fmt"
        "q"
)

func main() {
        var a q.A
        var b q.B // i'm a named unnamed type !!!

        fmt.Printf("%T\t%T\n", a, b)
}

What did you expect to see?

deadwood(~/src) % go run main.go
q.A     q.B

What did you see instead?

deadwood(~/src) % go run main.go
q.A     []int

Discussion

Aliases shouldn't not apply to unnamed type. Their is no "code repair" story in moving from one unnamed type to another. Allowing aliases on unnamed types means I can no longer teach Go as simply named and unnamed types. Instead I have to say

oh, unless it's an alias, in which case you have to remember that it could be an unnamed type, even when you import to from another package.

And worse, it will enable people to promulgate readability anti patterns like

type Any = interface{}

Please do not allow unnamed types to be aliased.

@cespare cespare changed the title aliases show not apply to unnamed types cmd/compile: aliases should not apply to unnamed types Feb 2, 2017
@griesemer
Copy link
Contributor

I'm going to close this because this is not a bug report. The current implementation follows the design document https://github.com/golang/proposal/blob/master/design/18130-type-alias.md exactly and thus is working as intended.

There may be an issue with the design, but the right place to discuss that is with #18130 . The proposal has been discussed at length and so has the design document which outlines this exact behavior and the need for possible spec changes in detail.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants