Commit 2565b5c0 authored by Russ Cox's avatar Russ Cox

cmd/gc: drop parenthesization restriction for receiver types

Matches CL 101500044.

LGTM=gri
R=gri
CC=golang-codereviews
https://golang.org/cl/110160044
parent b0c586a8
...@@ -974,7 +974,6 @@ static int opprec[] = { ...@@ -974,7 +974,6 @@ static int opprec[] = {
[OTFUNC] = 8, [OTFUNC] = 8,
[OTINTER] = 8, [OTINTER] = 8,
[OTMAP] = 8, [OTMAP] = 8,
[OTPAREN] = 8,
[OTSTRUCT] = 8, [OTSTRUCT] = 8,
[OINDEXMAP] = 8, [OINDEXMAP] = 8,
...@@ -1140,9 +1139,6 @@ exprfmt(Fmt *f, Node *n, int prec) ...@@ -1140,9 +1139,6 @@ exprfmt(Fmt *f, Node *n, int prec)
return fmtprint(f, "[]%N", n->left); return fmtprint(f, "[]%N", n->left);
return fmtprint(f, "[]%N", n->right); // happens before typecheck return fmtprint(f, "[]%N", n->right); // happens before typecheck
case OTPAREN:
return fmtprint(f, "(%N)", n->left);
case OTMAP: case OTMAP:
return fmtprint(f, "map[%N]%N", n->left, n->right); return fmtprint(f, "map[%N]%N", n->left, n->right);
......
...@@ -574,7 +574,6 @@ enum ...@@ -574,7 +574,6 @@ enum
OTINTER, // interface{} OTINTER, // interface{}
OTFUNC, // func() OTFUNC, // func()
OTARRAY, // []int, [8]int, [N]int or [...]int OTARRAY, // []int, [8]int, [N]int or [...]int
OTPAREN, // (T)
// misc // misc
ODDD, // func f(args ...int) or f(l...) or var a = [...]int{0, 1, 2}. ODDD, // func f(args ...int) or f(l...) or var a = [...]int{0, 1, 2}.
......
...@@ -1180,7 +1180,7 @@ ntype: ...@@ -1180,7 +1180,7 @@ ntype:
| dotname | dotname
| '(' ntype ')' | '(' ntype ')'
{ {
$$ = nod(OTPAREN, $2, N); $$ = $2;
} }
non_expr_type: non_expr_type:
...@@ -1199,7 +1199,7 @@ non_recvchantype: ...@@ -1199,7 +1199,7 @@ non_recvchantype:
| dotname | dotname
| '(' ntype ')' | '(' ntype ')'
{ {
$$ = nod(OTPAREN, $2, N); $$ = $2;
} }
convtype: convtype:
...@@ -1366,8 +1366,6 @@ fndcl: ...@@ -1366,8 +1366,6 @@ fndcl:
yyerror("bad receiver in method"); yyerror("bad receiver in method");
break; break;
} }
if(rcvr->right->op == OTPAREN || (rcvr->right->op == OIND && rcvr->right->left->op == OTPAREN))
yyerror("cannot parenthesize receiver type");
t = nod(OTFUNC, rcvr, N); t = nod(OTFUNC, rcvr, N);
t->list = $6; t->list = $6;
......
...@@ -382,16 +382,6 @@ reswitch: ...@@ -382,16 +382,6 @@ reswitch:
if(n->type == T) if(n->type == T)
goto error; goto error;
break; break;
case OTPAREN:
ok |= Etype;
l = typecheck(&n->left, Etype);
if(l->type == T)
goto error;
n->op = OTYPE;
n->type = l->type;
n->left = N;
break;
case OTARRAY: case OTARRAY:
ok |= Etype; ok |= Etype;
......
...@@ -678,8 +678,8 @@ static const yytype_uint16 yyrline[] = ...@@ -678,8 +678,8 @@ static const yytype_uint16 yyrline[] =
1180, 1181, 1187, 1188, 1189, 1190, 1196, 1197, 1198, 1199, 1180, 1181, 1187, 1188, 1189, 1190, 1196, 1197, 1198, 1199,
1200, 1206, 1207, 1210, 1213, 1214, 1215, 1216, 1217, 1220, 1200, 1206, 1207, 1210, 1213, 1214, 1215, 1216, 1217, 1220,
1221, 1234, 1238, 1243, 1248, 1253, 1257, 1258, 1261, 1267, 1221, 1234, 1238, 1243, 1248, 1253, 1257, 1258, 1261, 1267,
1274, 1280, 1287, 1293, 1304, 1318, 1347, 1387, 1412, 1430, 1274, 1280, 1287, 1293, 1304, 1319, 1348, 1386, 1411, 1429,
1439, 1442, 1450, 1454, 1458, 1465, 1471, 1476, 1488, 1491, 1438, 1441, 1449, 1453, 1457, 1464, 1470, 1475, 1487, 1490,
1501, 1502, 1508, 1509, 1515, 1519, 1525, 1526, 1532, 1536, 1501, 1502, 1508, 1509, 1515, 1519, 1525, 1526, 1532, 1536,
1542, 1565, 1570, 1576, 1582, 1589, 1598, 1607, 1622, 1628, 1542, 1565, 1570, 1576, 1582, 1589, 1598, 1607, 1622, 1628,
1633, 1637, 1644, 1657, 1658, 1664, 1670, 1673, 1677, 1683, 1633, 1637, 1644, 1657, 1658, 1664, 1670, 1673, 1677, 1683,
...@@ -3698,7 +3698,7 @@ yyreduce: ...@@ -3698,7 +3698,7 @@ yyreduce:
case 171: case 171:
#line 1182 "go.y" #line 1182 "go.y"
{ {
(yyval.node) = nod(OTPAREN, (yyvsp[(2) - (3)].node), N); (yyval.node) = (yyvsp[(2) - (3)].node);
} }
break; break;
...@@ -3712,7 +3712,7 @@ yyreduce: ...@@ -3712,7 +3712,7 @@ yyreduce:
case 180: case 180:
#line 1201 "go.y" #line 1201 "go.y"
{ {
(yyval.node) = nod(OTPAREN, (yyvsp[(2) - (3)].node), N); (yyval.node) = (yyvsp[(2) - (3)].node);
} }
break; break;
...@@ -3834,7 +3834,7 @@ yyreduce: ...@@ -3834,7 +3834,7 @@ yyreduce:
break; break;
case 205: case 205:
#line 1319 "go.y" #line 1320 "go.y"
{ {
Node *t; Node *t;
...@@ -3866,7 +3866,7 @@ yyreduce: ...@@ -3866,7 +3866,7 @@ yyreduce:
break; break;
case 206: case 206:
#line 1348 "go.y" #line 1349 "go.y"
{ {
Node *rcvr, *t; Node *rcvr, *t;
...@@ -3887,8 +3887,6 @@ yyreduce: ...@@ -3887,8 +3887,6 @@ yyreduce:
yyerror("bad receiver in method"); yyerror("bad receiver in method");
break; break;
} }
if(rcvr->right->op == OTPAREN || (rcvr->right->op == OIND && rcvr->right->left->op == OTPAREN))
yyerror("cannot parenthesize receiver type");
t = nod(OTFUNC, rcvr, N); t = nod(OTFUNC, rcvr, N);
t->list = (yyvsp[(6) - (8)].list); t->list = (yyvsp[(6) - (8)].list);
...@@ -3907,7 +3905,7 @@ yyreduce: ...@@ -3907,7 +3905,7 @@ yyreduce:
break; break;
case 207: case 207:
#line 1388 "go.y" #line 1387 "go.y"
{ {
Sym *s; Sym *s;
Type *t; Type *t;
...@@ -3935,7 +3933,7 @@ yyreduce: ...@@ -3935,7 +3933,7 @@ yyreduce:
break; break;
case 208: case 208:
#line 1413 "go.y" #line 1412 "go.y"
{ {
(yyval.node) = methodname1(newname((yyvsp[(4) - (8)].sym)), (yyvsp[(2) - (8)].list)->n->right); (yyval.node) = methodname1(newname((yyvsp[(4) - (8)].sym)), (yyvsp[(2) - (8)].list)->n->right);
(yyval.node)->type = functype((yyvsp[(2) - (8)].list)->n, (yyvsp[(6) - (8)].list), (yyvsp[(8) - (8)].list)); (yyval.node)->type = functype((yyvsp[(2) - (8)].list)->n, (yyvsp[(6) - (8)].list), (yyvsp[(8) - (8)].list));
...@@ -3954,7 +3952,7 @@ yyreduce: ...@@ -3954,7 +3952,7 @@ yyreduce:
break; break;
case 209: case 209:
#line 1431 "go.y" #line 1430 "go.y"
{ {
(yyvsp[(3) - (5)].list) = checkarglist((yyvsp[(3) - (5)].list), 1); (yyvsp[(3) - (5)].list) = checkarglist((yyvsp[(3) - (5)].list), 1);
(yyval.node) = nod(OTFUNC, N, N); (yyval.node) = nod(OTFUNC, N, N);
...@@ -3964,14 +3962,14 @@ yyreduce: ...@@ -3964,14 +3962,14 @@ yyreduce:
break; break;
case 210: case 210:
#line 1439 "go.y" #line 1438 "go.y"
{ {
(yyval.list) = nil; (yyval.list) = nil;
} }
break; break;
case 211: case 211:
#line 1443 "go.y" #line 1442 "go.y"
{ {
(yyval.list) = (yyvsp[(2) - (3)].list); (yyval.list) = (yyvsp[(2) - (3)].list);
if((yyval.list) == nil) if((yyval.list) == nil)
...@@ -3980,21 +3978,21 @@ yyreduce: ...@@ -3980,21 +3978,21 @@ yyreduce:
break; break;
case 212: case 212:
#line 1451 "go.y" #line 1450 "go.y"
{ {
(yyval.list) = nil; (yyval.list) = nil;
} }
break; break;
case 213: case 213:
#line 1455 "go.y" #line 1454 "go.y"
{ {
(yyval.list) = list1(nod(ODCLFIELD, N, (yyvsp[(1) - (1)].node))); (yyval.list) = list1(nod(ODCLFIELD, N, (yyvsp[(1) - (1)].node)));
} }
break; break;
case 214: case 214:
#line 1459 "go.y" #line 1458 "go.y"
{ {
(yyvsp[(2) - (3)].list) = checkarglist((yyvsp[(2) - (3)].list), 0); (yyvsp[(2) - (3)].list) = checkarglist((yyvsp[(2) - (3)].list), 0);
(yyval.list) = (yyvsp[(2) - (3)].list); (yyval.list) = (yyvsp[(2) - (3)].list);
...@@ -4002,14 +4000,14 @@ yyreduce: ...@@ -4002,14 +4000,14 @@ yyreduce:
break; break;
case 215: case 215:
#line 1466 "go.y" #line 1465 "go.y"
{ {
closurehdr((yyvsp[(1) - (1)].node)); closurehdr((yyvsp[(1) - (1)].node));
} }
break; break;
case 216: case 216:
#line 1472 "go.y" #line 1471 "go.y"
{ {
(yyval.node) = closurebody((yyvsp[(3) - (4)].list)); (yyval.node) = closurebody((yyvsp[(3) - (4)].list));
fixlbrace((yyvsp[(2) - (4)].i)); fixlbrace((yyvsp[(2) - (4)].i));
...@@ -4017,21 +4015,21 @@ yyreduce: ...@@ -4017,21 +4015,21 @@ yyreduce:
break; break;
case 217: case 217:
#line 1477 "go.y" #line 1476 "go.y"
{ {
(yyval.node) = closurebody(nil); (yyval.node) = closurebody(nil);
} }
break; break;
case 218: case 218:
#line 1488 "go.y" #line 1487 "go.y"
{ {
(yyval.list) = nil; (yyval.list) = nil;
} }
break; break;
case 219: case 219:
#line 1492 "go.y" #line 1491 "go.y"
{ {
(yyval.list) = concat((yyvsp[(1) - (3)].list), (yyvsp[(2) - (3)].list)); (yyval.list) = concat((yyvsp[(1) - (3)].list), (yyvsp[(2) - (3)].list));
if(nsyntaxerrors == 0) if(nsyntaxerrors == 0)
......
...@@ -21,7 +21,9 @@ type T struct { ...@@ -21,7 +21,9 @@ type T struct {
// legal according to spec // legal according to spec
func (p T) m() {} func (p T) m() {}
// not legal according to spec // now legal according to spec
func (p (T)) f() {} // ERROR "parenthesize|expected" func (p (T)) f() {}
func (p *(T)) g() {} // ERROR "parenthesize|expected" func (p *(T)) g() {}
func (p (*T)) h() {} // ERROR "parenthesize|expected" func (p (*T)) h() {}
func (p (*(T))) i() {}
func ((T),) j() {}
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