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/02/12 19:24:52 UTC
[groovy] branch GROOVY_3_0_X updated: minor edits
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 88ac481 minor edits
88ac481 is described below
commit 88ac48102dccc5dd64b94ef37d56d9845210342b
Author: Eric Milles <er...@thomsonreuters.com>
AuthorDate: Wed Feb 12 13:07:25 2020 -0600
minor edits
---
.../groovy/runtime/callsite/PogoMetaClassSite.java | 11 ++-
src/test/groovy/bugs/Groovy9387.groovy | 7 +-
.../groovy/transform/stc/STCAssignmentTest.groovy | 86 +++++++++++-----------
3 files changed, 53 insertions(+), 51 deletions(-)
diff --git a/src/main/java/org/codehaus/groovy/runtime/callsite/PogoMetaClassSite.java b/src/main/java/org/codehaus/groovy/runtime/callsite/PogoMetaClassSite.java
index 8c172fb..096d038 100644
--- a/src/main/java/org/codehaus/groovy/runtime/callsite/PogoMetaClassSite.java
+++ b/src/main/java/org/codehaus/groovy/runtime/callsite/PogoMetaClassSite.java
@@ -63,8 +63,15 @@ public class PogoMetaClassSite extends MetaClassSite {
if (e instanceof MissingMethodExecutionFailed) {
throw (MissingMethodException) e.getCause();
} else if (receiver.getClass() == e.getType() && e.getMethod().equals(name)) {
- // in case there's nothing else, invoke the object's own invokeMethod()
- return receiver.invokeMethod(name, args);
+ // in case there's nothing else, invoke the receiver's own invokeMethod()
+ try {
+ return receiver.invokeMethod(name, args);
+ } catch (MissingMethodException mme) {
+ if (mme instanceof MissingMethodExecutionFailed)
+ throw (MissingMethodException) mme.getCause();
+ // GROOVY-9387: in rare cases, this form still works
+ return metaClass.invokeMethod(receiver, name, args);
+ }
} else {
throw e;
}
diff --git a/src/test/groovy/bugs/Groovy9387.groovy b/src/test/groovy/bugs/Groovy9387.groovy
index 93eada5..1a8e775 100644
--- a/src/test/groovy/bugs/Groovy9387.groovy
+++ b/src/test/groovy/bugs/Groovy9387.groovy
@@ -18,13 +18,10 @@
*/
package groovy.bugs
-import groovy.test.NotYetImplemented
import groovy.transform.CompileStatic
-import org.codehaus.groovy.control.CompilerConfiguration
import org.junit.Test
import static groovy.test.GroovyAssert.assertScript
-import static org.junit.Assume.assumeFalse
@CompileStatic
final class Groovy9387 {
@@ -60,10 +57,8 @@ final class Groovy9387 {
'''
}
- @Test @NotYetImplemented
+ @Test
void testThisSetProperty() {
- // currently only broken for classic bytecode (TODO: remove assumeFalse line and this comment once issue is fixed - no harm in having an indy testcase at that point)
- assumeFalse CompilerConfiguration.DEFAULT.optimizationOptions?.indy
assertScript SUPPORT_ADAPTER + '''
class C extends BuilderSupportAdapter {
String value = 'abc'
diff --git a/src/test/groovy/transform/stc/STCAssignmentTest.groovy b/src/test/groovy/transform/stc/STCAssignmentTest.groovy
index d691ad2..cb688cc 100644
--- a/src/test/groovy/transform/stc/STCAssignmentTest.groovy
+++ b/src/test/groovy/transform/stc/STCAssignmentTest.groovy
@@ -24,118 +24,118 @@ package groovy.transform.stc
class STCAssignmentTest extends StaticTypeCheckingTestCase {
void testAssignmentFailure() {
- shouldFailWithMessages """
+ shouldFailWithMessages '''
int x = new Object()
- """, "Cannot assign value of type java.lang.Object to variable of type int"
+ ''', 'Cannot assign value of type java.lang.Object to variable of type int'
}
void testAssignmentFailure2() {
- shouldFailWithMessages """
+ shouldFailWithMessages '''
Set set = new Object()
- """, "Cannot assign value of type java.lang.Object to variable of type java.util.Set"
+ ''', 'Cannot assign value of type java.lang.Object to variable of type java.util.Set'
}
void testAssignmentFailure3() {
- shouldFailWithMessages """
+ shouldFailWithMessages '''
Set set = new Integer(2)
- """, "Cannot assign value of type java.lang.Integer to variable of type java.util.Set"
+ ''', 'Cannot assign value of type java.lang.Integer to variable of type java.util.Set'
}
void testIndirectAssignment() {
- shouldFailWithMessages """
+ shouldFailWithMessages '''
def o = new Object()
int x = o
- """, "Cannot assign value of type java.lang.Object to variable of type int"
+ ''', 'Cannot assign value of type java.lang.Object to variable of type int'
}
void testIndirectAssignment2() {
- shouldFailWithMessages """
+ shouldFailWithMessages '''
def o = new Object()
Set set = o
- """, "Cannot assign value of type java.lang.Object to variable of type java.util.Set"
+ ''', 'Cannot assign value of type java.lang.Object to variable of type java.util.Set'
}
void testIndirectAssignment3() {
- shouldFailWithMessages """
+ shouldFailWithMessages '''
int x = 2
Set set = x
- """, "Cannot assign value of type int to variable of type java.util.Set"
+ ''', 'Cannot assign value of type int to variable of type java.util.Set'
}
void testAssignmentToEnum() {
- assertScript """
+ assertScript '''
enum MyEnum { a, b, c }
MyEnum e = MyEnum.a
e = 'a' // string to enum is implicit
e = "${'a'}" // gstring to enum is implicit too
- """
+ '''
}
void testAssignmentToEnumFailure() {
- shouldFailWithMessages """
+ shouldFailWithMessages '''
enum MyEnum { a, b, c }
MyEnum e = MyEnum.a
e = 1
- """, "Cannot assign value of type int to variable of type MyEnum"
+ ''', 'Cannot assign value of type int to variable of type MyEnum'
}
void testAssignmentToString() {
- assertScript """
+ assertScript '''
String str = new Object()
- """
+ '''
}
void testAssignmentToBoolean() {
- assertScript """
+ assertScript '''
boolean test = new Object()
- """
+ '''
}
void testAssignmentToBooleanClass() {
- assertScript """
+ assertScript '''
Boolean test = new Object()
- """
+ '''
}
void testAssignmentToClass() {
- assertScript """
+ assertScript '''
Class test = 'java.lang.String'
- """
+ '''
}
void testPlusEqualsOnInt() {
- assertScript """
+ assertScript '''
int i = 0
i += 1
- """
+ '''
}
void testMinusEqualsOnInt() {
- assertScript """
+ assertScript '''
int i = 0
i -= 1
- """
+ '''
}
void testIntPlusEqualsObject() {
- shouldFailWithMessages """
+ shouldFailWithMessages '''
int i = 0
i += new Object()
- """, "Cannot find matching method int#plus(java.lang.Object)"
+ ''', 'Cannot find matching method int#plus(java.lang.Object)'
}
void testIntMinusEqualsObject() {
- shouldFailWithMessages """
+ shouldFailWithMessages '''
int i = 0
i -= new Object()
- """, "Cannot find matching method int#minus(java.lang.Object)"
+ ''', 'Cannot find matching method int#minus(java.lang.Object)'
}
void testStringPlusEqualsString() {
- assertScript """
+ assertScript '''
String str = 'test'
- str+='test2'
- """
+ str += 'test2'
+ '''
}
// GROOVY-9385
@@ -383,16 +383,16 @@ class STCAssignmentTest extends StaticTypeCheckingTestCase {
''', 'Cannot assign value of type java.lang.Object to variable of type char'
}
+ // GROOVY-6577
void testCastNullToBoolean() {
- // GROOVY-6577
assertScript '''
boolean c = null
assert c == false
'''
}
+ // GROOVY-6577
void testCastNullToBooleanWithExplicitCast() {
- // GROOVY-6577
assertScript '''
boolean c = (boolean) null
assert c == false
@@ -753,8 +753,8 @@ class STCAssignmentTest extends StaticTypeCheckingTestCase {
public MyInteger(String s) {super(s)}
}
- BigDecimal d = new MyDecimal("3.0")
- BigInteger i = new MyInteger("3")
+ BigDecimal d = new MyDecimal('3.0')
+ BigInteger i = new MyInteger('3')
'''
}
@@ -910,7 +910,7 @@ class STCAssignmentTest extends StaticTypeCheckingTestCase {
assertScript '''
class Base {}
class Derived extends Base {
- public String sayHello() { "hello"}
+ public String sayHello() { 'hello' }
}
class GBase<T extends Base> {
@@ -922,7 +922,7 @@ class STCAssignmentTest extends StaticTypeCheckingTestCase {
}
GDerived d = new GDerived();
- assert d.method() == "hello"
+ assert d.method() == 'hello'
'''
}
@@ -961,7 +961,7 @@ class STCAssignmentTest extends StaticTypeCheckingTestCase {
void testMultiAssign() {
assertScript '''
def m() {
- def row = ["", "", ""]
+ def row = ['', '', '']
def (left, right) = [row[0], row[1]]
left.toUpperCase()
}
@@ -1049,6 +1049,6 @@ class STCAssignmentTest extends StaticTypeCheckingTestCase {
def m(A2 a2) {
C1 c1 = (C1) a2
}
- ''', "Inconvertible types: cannot cast A2 to C1"
+ ''', 'Inconvertible types: cannot cast A2 to C1'
}
}