mirror of
https://github.com/golang/go
synced 2024-11-11 21:50:21 -07:00
cmd/gc: allow new conversion syntax
For consistency with conversions that look like function calls, conversions that don't look like function calls now allow an optional trailing comma. That is, int(x,) has always been syntactically valid. Now []int(x,) is valid too. Fixes #4162. R=ken2 CC=golang-dev https://golang.org/cl/7288045
This commit is contained in:
parent
2af3cbe308
commit
ffc742b658
@ -947,7 +947,7 @@ pexpr_no_paren:
|
||||
$$ = nod(OSLICE, $1, nod(OKEY, $3, $5));
|
||||
}
|
||||
| pseudocall
|
||||
| convtype '(' expr ')'
|
||||
| convtype '(' expr ocomma ')'
|
||||
{
|
||||
// conversion
|
||||
$$ = nod(OCALL, $1, N);
|
||||
|
1304
src/cmd/gc/y.tab.c
1304
src/cmd/gc/y.tab.c
File diff suppressed because it is too large
Load Diff
@ -26,7 +26,7 @@ static struct {
|
||||
237, ';',
|
||||
"unexpected semicolon or newline before {",
|
||||
|
||||
474, LBODY,
|
||||
475, LBODY,
|
||||
"unexpected semicolon or newline before {",
|
||||
|
||||
22, '{',
|
||||
@ -44,7 +44,7 @@ static struct {
|
||||
37, ',',
|
||||
"unexpected comma in channel type",
|
||||
|
||||
437, LELSE,
|
||||
438, LELSE,
|
||||
"unexpected semicolon or newline before else",
|
||||
|
||||
257, ',',
|
||||
@ -65,12 +65,12 @@ static struct {
|
||||
425, ';',
|
||||
"need trailing comma before newline in composite literal",
|
||||
|
||||
435, ';',
|
||||
436, ';',
|
||||
"need trailing comma before newline in composite literal",
|
||||
|
||||
112, LNAME,
|
||||
"nested func not allowed",
|
||||
|
||||
641, ';',
|
||||
642, ';',
|
||||
"else must be followed by if or statement block"
|
||||
};
|
||||
|
17
test/fixedbugs/issue4162.go
Normal file
17
test/fixedbugs/issue4162.go
Normal file
@ -0,0 +1,17 @@
|
||||
// compile
|
||||
|
||||
// Copyright 2013 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Issue 4162. Trailing commas now allowed in conversions.
|
||||
|
||||
package p
|
||||
|
||||
// All these are valid now.
|
||||
var (
|
||||
_ = int(1.0,) // comma was always permitted (like function call)
|
||||
_ = []byte("foo",) // was syntax error: unexpected comma
|
||||
_ = chan int(nil,) // was syntax error: unexpected comma
|
||||
_ = (func())(nil,) // was syntax error: unexpected comma
|
||||
)
|
Loading…
Reference in New Issue
Block a user