Commit ffc742b6 authored by Russ Cox's avatar Russ Cox

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
parent 2af3cbe3
......@@ -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);
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -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"
};
// 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
)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment