You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2017/02/08 04:12:32 UTC
[08/11] groovy git commit: GROOVY-8030: An unexpected error has
occurred when using 'kkk = kkk + 12' (closes #488)
GROOVY-8030: An unexpected error has occurred when using 'kkk = kkk + 12' (closes #488)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/4971552b
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/4971552b
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/4971552b
Branch: refs/heads/parrot
Commit: 4971552b85e5c12d4ebf49ddac181523c5160baa
Parents: ea28001
Author: paulk <pa...@asert.com.au>
Authored: Fri Feb 3 19:59:47 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Sun Feb 5 11:33:11 2017 +1000
----------------------------------------------------------------------
.../asm/sc/StaticTypesCallSiteWriter.java | 5 +++
src/test/groovy/bugs/Groovy8030Bug.groovy | 34 ++++++++++++++++++++
2 files changed, 39 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/4971552b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
index fe69531..727739d 100644
--- a/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
+++ b/src/main/org/codehaus/groovy/classgen/asm/sc/StaticTypesCallSiteWriter.java
@@ -631,6 +631,11 @@ public class StaticTypesCallSiteWriter extends CallSiteWriter implements Opcodes
}
// now try with flow type instead of declaration type
rType = receiver.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
+ if (receiver instanceof VariableExpression && receiver.getNodeMetaData().isEmpty()) {
+ // TODO: can STCV be made smarter to avoid this check?
+ VariableExpression ve = (VariableExpression) ((VariableExpression)receiver).getAccessedVariable();
+ rType = ve.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
+ }
if (rType!=null && trySubscript(receiver, message, arguments, rType, aType)) {
return;
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/4971552b/src/test/groovy/bugs/Groovy8030Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy8030Bug.groovy b/src/test/groovy/bugs/Groovy8030Bug.groovy
new file mode 100644
index 0000000..5438989
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8030Bug.groovy
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovy.bugs
+
+class Groovy8030Bug extends GroovyTestCase {
+ void testCompileStaticWithBinaryExpressionAndFlowTyping() {
+ assertScript """
+@groovy.transform.CompileStatic
+def main() {
+ def kkk = "abc"
+ kkk = 30
+ kkk + 12 // Previously: BUG! exception in phase 'class generation'
+}
+
+assert main() == 42
+ """
+ }
+}