You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2015/06/23 07:46:52 UTC
incubator-groovy git commit: GROOVY-5185: Cast operator precedence is
incorrect
Repository: incubator-groovy
Updated Branches:
refs/heads/master ca7779e4e -> e45962bac
GROOVY-5185: Cast operator precedence is incorrect
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/e45962ba
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/e45962ba
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/e45962ba
Branch: refs/heads/master
Commit: e45962bac297aff590e9e53ff55a9e06ac647f36
Parents: ca7779e
Author: Paul King <pa...@asert.com.au>
Authored: Tue Jun 23 15:26:02 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Tue Jun 23 15:46:02 2015 +1000
----------------------------------------------------------------------
src/main/org/codehaus/groovy/antlr/groovy.g | 8 ++++----
src/test/gls/syntax/ParsingTest.groovy | 16 ++++++++++++++++
2 files changed, 20 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/e45962ba/src/main/org/codehaus/groovy/antlr/groovy.g
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/antlr/groovy.g b/src/main/org/codehaus/groovy/antlr/groovy.g
index be80bfc..bcd7d93 100644
--- a/src/main/org/codehaus/groovy/antlr/groovy.g
+++ b/src/main/org/codehaus/groovy/antlr/groovy.g
@@ -2320,10 +2320,10 @@ commandArgument
// in contexts where we know we have an expression. It allows general Java-type expressions.
expression[int lc_stmt]
:
- (LPAREN typeSpec[true] RPAREN expression[lc_stmt])=>
- lp:LPAREN^ {#lp.setType(TYPECAST);} typeSpec[true] RPAREN!
- expression[lc_stmt]
- |
+// (LPAREN typeSpec[true] RPAREN expression[lc_stmt])=>
+// lp:LPAREN^ {#lp.setType(TYPECAST);} typeSpec[true] RPAREN!
+// expression[lc_stmt]
+// |
(LPAREN nls IDENT (COMMA nls IDENT)* RPAREN ASSIGN) =>
m:multipleAssignment[lc_stmt] {#expression=#m;}
| assignmentExpression[lc_stmt]
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/e45962ba/src/test/gls/syntax/ParsingTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/gls/syntax/ParsingTest.groovy b/src/test/gls/syntax/ParsingTest.groovy
index 79f9365..f126c2a 100644
--- a/src/test/gls/syntax/ParsingTest.groovy
+++ b/src/test/gls/syntax/ParsingTest.groovy
@@ -53,6 +53,22 @@ public class ParsingTest extends gls.CompilableTestSupport {
assert val4.class.componentType == short
}
+ void testCastPrecedence_Groovy4421_Groovy5185() {
+ def i = (int)1/(int)2
+ assert i.class==BigDecimal
+
+ def result = (long)10.7 % 3L
+ assert result == 1 && result instanceof Long
+
+ assert '42' == (String) { -> 40 + 2 }.call()
+
+ def percentage = 5.3
+ assert '5%' == (int)Math.floor(percentage) + "%"
+
+ def someInt = Integer.MAX_VALUE
+ assert 4294967294L == (long)someInt + someInt
+ }
+
void testExpressionParsingWithCastInFrontOfAMap() {
shouldCompile """
def m = (Map)[a:{ "foo"; println 'bar' }]