Skip to content

Commit 89632aa

Browse files
committed
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 <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Matthew Dempsky <[email protected]>
1 parent 8b07ec2 commit 89632aa

File tree

6 files changed

+4
-10
lines changed

6 files changed

+4
-10
lines changed

src/cmd/compile/internal/gc/bexport.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
The export data is a serialized description of the graph of exported
1212
"objects": constants, types, variables, and functions. Aliases may be
1313
directly reexported, and unaliased types may be indirectly reexported
14-
(as part of the type of a directly exorted object). More generally,
14+
(as part of the type of a directly exported object). More generally,
1515
objects referred to from inlined function bodies can be reexported.
1616
We need to know which package declares these reexported objects, and
1717
therefore packages are also part of the export graph.

src/cmd/compile/internal/syntax/parser.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -365,8 +365,7 @@ func (p *parser) typeDecl(group *Group) Decl {
365365
}
366366

367367
name := p.name()
368-
// permit both: type T => p.T and: type T = p.T for now
369-
if p.got(_Rarrow) || p.got(_Assign) {
368+
if p.got(_Rarrow) {
370369
return p.aliasDecl(Type, name, group)
371370
}
372371

src/go/parser/parser.go

+1-2
Original file line numberDiff line numberDiff line change
@@ -2343,8 +2343,7 @@ func (p *parser) parseTypeSpec(doc *ast.CommentGroup, _ token.Token, _ int) ast.
23432343
}
23442344

23452345
ident := p.parseIdent()
2346-
// permit both: type T => p.T and: type T = p.T for now
2347-
if p.tok == token.ALIAS || p.tok == token.ASSIGN {
2346+
if p.tok == token.ALIAS {
23482347
p.next()
23492348
return p.parseAliasSpec(doc, ast.Typ, ident)
23502349
}

src/go/parser/short_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var valids = []string{
4747
`package p; var _ = map[P]int{P{}:0, {}:1}`,
4848
`package p; var _ = map[*P]int{&P{}:0, {}:1}`,
4949
`package p; const c => p.C; var x => X; type T => p.T; func F => p.F`,
50-
`package p; var (_ int; x => p.X; y => Y); type (t => T; t1 = p.T1)`,
50+
`package p; var (_ int; x => p.X; y => Y); type (t => T; t1 => p.T1)`,
5151
}
5252

5353
func TestValid(t *testing.T) {

src/go/printer/testdata/declarations.golden

-2
Original file line numberDiff line numberDiff line change
@@ -1015,8 +1015,6 @@ type c => p.C
10151015
type (
10161016
s struct{}
10171017
a => A
1018-
b => A
1019-
c => foo
10201018
ddd => p.Foo
10211019
)
10221020

src/go/printer/testdata/declarations.input

-2
Original file line numberDiff line numberDiff line change
@@ -1029,8 +1029,6 @@ type c => p.C
10291029
type (
10301030
s struct{}
10311031
a => A
1032-
b = A
1033-
c = foo
10341032
ddd => p.Foo
10351033
)
10361034

0 commit comments

Comments
 (0)