bradleyfalzon / apicompat

apicompat checks recent changes to a Go project for backwards incompatible changes
https://abicheck.bradleyf.id.au
MIT License
179 stars 5 forks source link

Monitor Alias Experiment #27

Open bradleyfalzon opened 7 years ago

bradleyfalzon commented 7 years ago

This may have far reaching consequences, or may not at all.

There's at least appears to be added ast.AliasSpec.

See CLs related to https://github.com/golang/go/issues/16339

bradleyfalzon commented 7 years ago

https://tip.golang.org/ref/spec#Alias_declarations

Alias declarations

An alias declaration binds an identifier, the alias, to a constant, type, variable, or function denoted by a qualified identifier and declared in a different package.

AliasSpec = identifier "=>" QualifiedIdent .

The effect of referring to a constant, type, variable, or function by an alias is indistinguishable from referring to it by its original name. For example, the type denoted by a type alias and the aliased type are identical.

An alias declaration may appear only as a form of constant, type, variable, or function declaration at the package level, and the aliased entity must be a constant, type, variable, or function respectively. Alias declarations inside functions are not permitted.

const (
    G  =  6.67408e-11      // regular and alias declarations may be grouped
    Pi => math.Pi          // same effect as: Pi = math.Pi
)

type Struct => types.Struct    // re-export of types.Struct

func sin => math.Sin           // non-exported shortcut for frequently used function

An alias declaration may not refer to package unsafe.

bradleyfalzon commented 7 years ago

It appears that aliases won't be implemented by 1.8 anymore: https://github.com/golang/go/issues/16339#issuecomment-258527920

dmitshur commented 6 years ago

They've been implemented as "type aliases" in Go 1.9:

https://golang.org/doc/go1.9#language

bradleyfalzon commented 6 years ago

Thanks for the reminder, and this should've been implemented a while ago. It's back on my radar, I've looked at it before and it appeared straightforward.