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 2022/08/29 16:22:27 UTC
[groovy] branch GROOVY_3_0_X updated: GROOVY-5502 (pt.1): STC: ignore `null` initializer for references
This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_3_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_3_0_X by this push:
new fee7857971 GROOVY-5502 (pt.1): STC: ignore `null` initializer for references
fee7857971 is described below
commit fee7857971975327b353a375893c5c6e0e90e9df
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Sun Dec 12 16:14:05 2021 -0600
GROOVY-5502 (pt.1): STC: ignore `null` initializer for references
---
.../transform/stc/StaticTypeCheckingVisitor.java | 3 +-
.../groovy/transform/stc/STCAssignmentTest.groovy | 33 ++++++++++++++++++----
2 files changed, 30 insertions(+), 6 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 30f73b36e6..83a1912e94 100644
--- a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -829,7 +829,8 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
}
}
- boolean isEmptyDeclaration = (expression instanceof DeclarationExpression && rightExpression instanceof EmptyExpression);
+ boolean isEmptyDeclaration = (expression instanceof DeclarationExpression
+ && (rightExpression instanceof EmptyExpression || rType == UNKNOWN_PARAMETER_TYPE));
if (!isEmptyDeclaration && isAssignment(op)) {
if (rightExpression instanceof ConstructorCallExpression)
inferDiamondType((ConstructorCallExpression) rightExpression, lType);
diff --git a/src/test/groovy/transform/stc/STCAssignmentTest.groovy b/src/test/groovy/transform/stc/STCAssignmentTest.groovy
index b852eff171..752c9c973b 100644
--- a/src/test/groovy/transform/stc/STCAssignmentTest.groovy
+++ b/src/test/groovy/transform/stc/STCAssignmentTest.groovy
@@ -550,13 +550,13 @@ class STCAssignmentTest extends StaticTypeCheckingTestCase {
void testIfWithCommonInterface() {
assertScript '''
interface I {
- def foo()
+ def m()
}
class A implements I {
- def foo() { 'A' }
+ def m() { 'A' }
}
class B implements I {
- def foo() { 'B' }
+ def m() { 'B' }
}
def x = new A()
@@ -564,13 +564,36 @@ class STCAssignmentTest extends StaticTypeCheckingTestCase {
if (y) {
x = new B()
}
- assert x.foo() == 'B'
+ assert x.m() == 'B'
'''
}
+ // GROOVY-5502
+ void testIfElseWithCommonSuperclass() {
+ for (val in ['null', 'new A()', 'new B()', 'new C()'/*TODO:, 'new Object()'*/]) {
+ assertScript """
+ class A {
+ def m() { 'A' }
+ }
+ class B extends A {
+ }
+ class C extends A {
+ }
+
+ def var = $val
+ if (true) {
+ var = new B()
+ } else {
+ var = new C()
+ }
+ assert var.m() == 'A' // Cannot find matching method Object#m()
+ """
+ }
+ }
+
// GROOVY-9786
void testIfElseIfWithCommonInterface() {
- ['I', 'def', 'var', 'Object'].each {
+ for (it in ['I', 'def', 'var', 'Object']) {
assertScript """
interface I {
def m()