From 7a42dddbe64f6f056f3940efd5758cfcd682bd90 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Fri, 2 Dec 2011 14:58:26 -0500 Subject: [PATCH] gc: fix line number for redundant print R=ken2 CC=golang-dev https://golang.org/cl/5434111 --- src/cmd/gc/go.y | 41 +++++++++++++++++++++++------------------ src/cmd/gc/typecheck.c | 2 +- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/src/cmd/gc/go.y b/src/cmd/gc/go.y index 81a02c01e4..a42a7488f7 100644 --- a/src/cmd/gc/go.y +++ b/src/cmd/gc/go.y @@ -66,7 +66,7 @@ static void fixlbrace(int); %type pseudocall range_stmt select_stmt %type simple_stmt %type switch_stmt uexpr -%type xfndcl typedcl +%type xfndcl typedcl start_complit %type xdcl fnbody fnres loop_body dcl_name_list %type new_name_list expr_list keyval_list braced_keyval_list expr_or_type_list xdcl_list @@ -900,29 +900,34 @@ pexpr_no_paren: $$ = nod(OCALL, $1, N); $$->list = list1($3); } -| comptype lbrace braced_keyval_list '}' +| comptype lbrace start_complit braced_keyval_list '}' { - // composite expression - $$ = nod(OCOMPLIT, N, $1); - $$->list = $3; - + $$ = $3; + $$->right = $1; + $$->list = $4; fixlbrace($2); } -| pexpr_no_paren '{' braced_keyval_list '}' +| pexpr_no_paren '{' start_complit braced_keyval_list '}' { - // composite expression - $$ = nod(OCOMPLIT, N, $1); - $$->list = $3; + $$ = $3; + $$->right = $1; + $$->list = $4; } -| '(' expr_or_type ')' '{' braced_keyval_list '}' +| '(' expr_or_type ')' '{' start_complit braced_keyval_list '}' { - yyerror("cannot parenthesize type in composite literal"); - // composite expression - $$ = nod(OCOMPLIT, N, $2); - $$->list = $5; + $$ = $5; + $$->right = $2; + $$->list = $6; } | fnliteral +start_complit: + { + // composite expression. + // make node early so we get the right line number. + $$ = nod(OCOMPLIT, N, N); + } + keyval: expr ':' complitexpr { @@ -931,10 +936,10 @@ keyval: complitexpr: expr -| '{' braced_keyval_list '}' +| '{' start_complit braced_keyval_list '}' { - $$ = nod(OCOMPLIT, N, N); - $$->list = $2; + $$ = $2; + $$->list = $3; } pexpr: diff --git a/src/cmd/gc/typecheck.c b/src/cmd/gc/typecheck.c index 8cd0dce334..802d6dcdc5 100644 --- a/src/cmd/gc/typecheck.c +++ b/src/cmd/gc/typecheck.c @@ -1994,7 +1994,7 @@ pushtype(Node *n, Type *t) else if(debug['s']) { typecheck(&n->right, Etype); if(n->right->type != T && eqtype(n->right->type, t)) - print("%lL: redundant type: %T\n", n->right->lineno, t); + print("%lL: redundant type: %T\n", n->lineno, t); } }