You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by em...@apache.org on 2020/12/31 17:51:54 UTC
[groovy] branch GROOVY_2_5_X updated: GROOVY-9863: save type into
synthetic property (backed by getter/setter)
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_2_5_X by this push:
new 6bd57fb GROOVY-9863: save type into synthetic property (backed by getter/setter)
6bd57fb is described below
commit 6bd57fbc126c3cc97a69d21d7d9ac4c4ea4f3e6f
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Dec 20 16:53:32 2020 -0600
GROOVY-9863: save type into synthetic property (backed by getter/setter)
VariableScopeVisitor#findClassMember makes PropertyNode for method-only
properties but does not set any type information on it.
---
.../transform/stc/StaticTypeCheckingVisitor.java | 6 ++++--
.../classgen/asm/sc/BugsStaticCompileTest.groovy | 23 ++++++++++++++++++++--
2 files changed, 25 insertions(+), 4 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index cdb2d3e..0d9d4dc 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -4045,8 +4045,10 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
if (accessedVariable != exp && accessedVariable instanceof VariableExpression) {
storeType((Expression) accessedVariable, cn);
}
- if (accessedVariable instanceof Parameter) {
- ((Parameter) accessedVariable).putNodeMetaData(INFERRED_TYPE, cn);
+ if (accessedVariable instanceof Parameter
+ || (accessedVariable instanceof PropertyNode
+ && ((PropertyNode) accessedVariable).getField().isSynthetic())) {
+ ((ASTNode) accessedVariable).putNodeMetaData(INFERRED_TYPE, cn);
}
if (var.isClosureSharedVariable() && cn != null) {
List<ClassNode> assignedTypes = typeCheckingContext.closureSharedVariablesAssignmentTypes.get(var);
diff --git a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
index 062054b..ed10ddd 100644
--- a/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
+++ b/src/test/org/codehaus/groovy/classgen/asm/sc/BugsStaticCompileTest.groovy
@@ -23,9 +23,10 @@ import groovy.transform.stc.BugsSTCTest
/**
* Unit tests for static type checking : bugs.
*/
-class BugsStaticCompileTest extends BugsSTCTest implements StaticCompilationTestSupport {
+final class BugsStaticCompileTest extends BugsSTCTest implements StaticCompilationTestSupport {
- void testGroovy5498PropertyAccess() {
+ // GROOVY-5498
+ void testPropertyAccess() {
assertScript '''
class Test {
@@ -117,6 +118,24 @@ class BugsStaticCompileTest extends BugsSTCTest implements StaticCompilationTest
'''
}
+ // GROOVY-9863
+ void testPlusShouldNotThrowGroovyBugError() {
+ assertScript '''
+ import static org.junit.Assert.assertEquals
+
+ class C {
+ double getSomeValue() {
+ 0.0d
+ }
+ double test() {
+ 1.0d + someValue
+ }
+ }
+
+ assertEquals(1.0d, new C().test(), 0.00000001d)
+ '''
+ }
+
// GROOVY-
void testPowerShouldNotThrowVerifyError() {
assertScript '''int squarePlusOne(int num) {