Skip to content

Commit 2b47e29

Browse files
committed
Fix YA unwanted behavioral difference with operator_precedence_warning.
Jeff Janes noted that the error cursor position shown for some errors would vary when operator_precedence_warning is turned on. We'd prefer that option to have no undocumented effects, so this isn't desirable. To fix, make sure that an AEXPR_PAREN node has the same exprLocation as its child node. (Note: it would be a little cheaper to use @2 here instead of an exprLocation call, but there are cases where that wouldn't produce the identical answer, so don't do it like that.) Back-patch to 9.5 where this feature was introduced. Discussion: https://postgr.es/m/CAMkU=1ykK+VhhcQ4Ky8KBo9FoaUJH3f3rDQB8TkTXi-ZsBRUkQ@mail.gmail.com
1 parent 660e457 commit 2b47e29

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/backend/parser/gram.y

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11958,7 +11958,10 @@ c_expr: columnref { $$ = $1; }
1195811958
* AEXPR_PAREN nodes wrapping all explicitly
1195911959
* parenthesized subexpressions; this prevents bogus
1196011960
* warnings from being issued when the ordering has
11961-
* been forced by parentheses.
11961+
* been forced by parentheses. Take care that an
11962+
* AEXPR_PAREN node has the same exprLocation as its
11963+
* child, so as not to cause surprising changes in
11964+
* error cursor positioning.
1196211965
*
1196311966
* In principle we should not be relying on a GUC to
1196411967
* decide whether to insert AEXPR_PAREN nodes.
@@ -11967,7 +11970,8 @@ c_expr: columnref { $$ = $1; }
1196711970
* we'd just as soon not waste cycles on dummy parse
1196811971
* nodes if we don't have to.
1196911972
*/
11970-
$$ = (Node *) makeA_Expr(AEXPR_PAREN, NIL, $2, NULL, @1);
11973+
$$ = (Node *) makeA_Expr(AEXPR_PAREN, NIL, $2, NULL,
11974+
exprLocation($2));
1197111975
}
1197211976
else
1197311977
$$ = $2;

0 commit comments

Comments
 (0)