diff --git a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java index fd6b3c6c6d..b9369a164a 100644 --- a/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java +++ b/base-test/org.eclipse.jdt.groovy.core.tests.compiler/src/org/eclipse/jdt/groovy/core/tests/basic/GroovySimpleTests.java @@ -1069,6 +1069,23 @@ public void testStaticProperty14() { "----------\n"); } + @Test // GROOVY-10159 + public void testStaticProperty15() { + //@formatter:off + String[] sources = { + "Main.groovy", + "public class Main {\n" + + " static final String foo = 1 + 1\n" + + " static main(args) {\n" + + " print(foo);\n" + + " }\n" + + "}\n", + }; + //@formatter:on + + runConformTest(sources, "2"); + } + @Test public void testClash_GRE1076() { //@formatter:off diff --git a/base/org.codehaus.groovy25/src/org/apache/groovy/ast/tools/ExpressionUtils.java b/base/org.codehaus.groovy25/src/org/apache/groovy/ast/tools/ExpressionUtils.java index 6c5492116c..08d4dd539e 100644 --- a/base/org.codehaus.groovy25/src/org/apache/groovy/ast/tools/ExpressionUtils.java +++ b/base/org.codehaus.groovy25/src/org/apache/groovy/ast/tools/ExpressionUtils.java @@ -82,6 +82,9 @@ public static ConstantExpression transformBinaryConstantExpression(BinaryExpress Expression left = transformInlineConstants(be.getLeftExpression(), targetType); Expression right = transformInlineConstants(be.getRightExpression(), targetType); if (left instanceof ConstantExpression && right instanceof ConstantExpression) { + // GRECLIPSE add -- GROOVY-10159 + if (((ConstantExpression) left).getValue() instanceof String) + // GRECLIPSE end return configure(be, new ConstantExpression((String) ((ConstantExpression) left).getValue() + ((ConstantExpression) right).getValue())); } diff --git a/base/org.codehaus.groovy30/src/org/apache/groovy/ast/tools/ExpressionUtils.java b/base/org.codehaus.groovy30/src/org/apache/groovy/ast/tools/ExpressionUtils.java index 6b1612c4af..1cd166c5db 100644 --- a/base/org.codehaus.groovy30/src/org/apache/groovy/ast/tools/ExpressionUtils.java +++ b/base/org.codehaus.groovy30/src/org/apache/groovy/ast/tools/ExpressionUtils.java @@ -77,6 +77,9 @@ public static ConstantExpression transformBinaryConstantExpression(final BinaryE Expression left = transformInlineConstants(be.getLeftExpression(), targetType); Expression right = transformInlineConstants(be.getRightExpression(), targetType); if (left instanceof ConstantExpression && right instanceof ConstantExpression) { + // GRECLIPSE add -- GROOVY-10159 + if (((ConstantExpression) left).getValue() instanceof String) + // GRECLIPSE end return configure(be, new ConstantExpression((String) ((ConstantExpression) left).getValue() + ((ConstantExpression) right).getValue())); } } diff --git a/base/org.codehaus.groovy40/src/org/apache/groovy/ast/tools/ExpressionUtils.java b/base/org.codehaus.groovy40/src/org/apache/groovy/ast/tools/ExpressionUtils.java index 75e4d4f037..064bbaf8d3 100644 --- a/base/org.codehaus.groovy40/src/org/apache/groovy/ast/tools/ExpressionUtils.java +++ b/base/org.codehaus.groovy40/src/org/apache/groovy/ast/tools/ExpressionUtils.java @@ -76,6 +76,9 @@ public static ConstantExpression transformBinaryConstantExpression(final BinaryE Expression left = transformInlineConstants(be.getLeftExpression(), targetType); Expression right = transformInlineConstants(be.getRightExpression(), targetType); if (left instanceof ConstantExpression && right instanceof ConstantExpression) { + // GRECLIPSE add -- GROOVY-10159 + if (((ConstantExpression) left).getValue() instanceof String) + // GRECLIPSE end return configure(be, new ConstantExpression((String) ((ConstantExpression) left).getValue() + ((ConstantExpression) right).getValue())); } }