mirror of
https://github.com/golang/go
synced 2024-11-24 10:00:12 -07:00
cmd/compile, go/parser: disallow "type T = p.T" - must use "=>"
I had added this originally so we can play with different notations but it doesn't make sense to keep it around since gofmt will convert a type alias declaration using "=" into one using "=>" anyhow. More importantly, the spec doesn't permit it. Change-Id: Icb010b5a9976aebf877e48b3ce9d7245559ca494 Reviewed-on: https://go-review.googlesource.com/32105 Run-TryBot: Robert Griesemer <gri@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
parent
8b07ec20f7
commit
89632aa183
@ -11,7 +11,7 @@
|
|||||||
The export data is a serialized description of the graph of exported
|
The export data is a serialized description of the graph of exported
|
||||||
"objects": constants, types, variables, and functions. Aliases may be
|
"objects": constants, types, variables, and functions. Aliases may be
|
||||||
directly reexported, and unaliased types may be indirectly reexported
|
directly reexported, and unaliased types may be indirectly reexported
|
||||||
(as part of the type of a directly exorted object). More generally,
|
(as part of the type of a directly exported object). More generally,
|
||||||
objects referred to from inlined function bodies can be reexported.
|
objects referred to from inlined function bodies can be reexported.
|
||||||
We need to know which package declares these reexported objects, and
|
We need to know which package declares these reexported objects, and
|
||||||
therefore packages are also part of the export graph.
|
therefore packages are also part of the export graph.
|
||||||
|
@ -365,8 +365,7 @@ func (p *parser) typeDecl(group *Group) Decl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
name := p.name()
|
name := p.name()
|
||||||
// permit both: type T => p.T and: type T = p.T for now
|
if p.got(_Rarrow) {
|
||||||
if p.got(_Rarrow) || p.got(_Assign) {
|
|
||||||
return p.aliasDecl(Type, name, group)
|
return p.aliasDecl(Type, name, group)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2343,8 +2343,7 @@ func (p *parser) parseTypeSpec(doc *ast.CommentGroup, _ token.Token, _ int) ast.
|
|||||||
}
|
}
|
||||||
|
|
||||||
ident := p.parseIdent()
|
ident := p.parseIdent()
|
||||||
// permit both: type T => p.T and: type T = p.T for now
|
if p.tok == token.ALIAS {
|
||||||
if p.tok == token.ALIAS || p.tok == token.ASSIGN {
|
|
||||||
p.next()
|
p.next()
|
||||||
return p.parseAliasSpec(doc, ast.Typ, ident)
|
return p.parseAliasSpec(doc, ast.Typ, ident)
|
||||||
}
|
}
|
||||||
|
@ -47,7 +47,7 @@ var valids = []string{
|
|||||||
`package p; var _ = map[P]int{P{}:0, {}:1}`,
|
`package p; var _ = map[P]int{P{}:0, {}:1}`,
|
||||||
`package p; var _ = map[*P]int{&P{}:0, {}:1}`,
|
`package p; var _ = map[*P]int{&P{}:0, {}:1}`,
|
||||||
`package p; const c => p.C; var x => X; type T => p.T; func F => p.F`,
|
`package p; const c => p.C; var x => X; type T => p.T; func F => p.F`,
|
||||||
`package p; var (_ int; x => p.X; y => Y); type (t => T; t1 = p.T1)`,
|
`package p; var (_ int; x => p.X; y => Y); type (t => T; t1 => p.T1)`,
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestValid(t *testing.T) {
|
func TestValid(t *testing.T) {
|
||||||
|
2
src/go/printer/testdata/declarations.golden
vendored
2
src/go/printer/testdata/declarations.golden
vendored
@ -1015,8 +1015,6 @@ type c => p.C
|
|||||||
type (
|
type (
|
||||||
s struct{}
|
s struct{}
|
||||||
a => A
|
a => A
|
||||||
b => A
|
|
||||||
c => foo
|
|
||||||
ddd => p.Foo
|
ddd => p.Foo
|
||||||
)
|
)
|
||||||
|
|
||||||
|
2
src/go/printer/testdata/declarations.input
vendored
2
src/go/printer/testdata/declarations.input
vendored
@ -1029,8 +1029,6 @@ type c => p.C
|
|||||||
type (
|
type (
|
||||||
s struct{}
|
s struct{}
|
||||||
a => A
|
a => A
|
||||||
b = A
|
|
||||||
c = foo
|
|
||||||
ddd => p.Foo
|
ddd => p.Foo
|
||||||
)
|
)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user