This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch GROOVY_4_0_X
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/GROOVY_4_0_X by this push:
new 99891281b4 GROOVY-10939: STC: static methods for class except from
`Class`/`Object`
99891281b4 is described below
commit 99891281b4e63cda240d6ed85b88da2aa2a3d643
Author: Eric Milles <[email protected]>
AuthorDate: Thu Feb 16 12:57:02 2023 -0600
GROOVY-10939: STC: static methods for class except from `Class`/`Object`
---
.../codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java | 4 ++--
src/test/groovy/transform/stc/MethodCallsSTCTest.groovy | 7 +++++++
2 files changed, 9 insertions(+), 2 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 2ebff42f40..142ae2c866 100644
---
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3500,8 +3500,8 @@ public class StaticTypeCheckingVisitor extends
ClassCodeVisitorSupport {
if (chosenReceiver == null) {
chosenReceiver =
Receiver.make(declaringClass.getPlainNodeReference());
}
- if (!targetMethodCandidate.isStatic() &&
!isClassType(declaringClass) && isClassType(receiver)
- && chosenReceiver.getData() == null &&
call.getNodeMetaData(DYNAMIC_RESOLUTION) == null) {
+ if (!targetMethodCandidate.isStatic() &&
!(isClassType(declaringClass) || isObjectType(declaringClass)) // GROOVY-10939:
Class or Object
+ && isClassType(receiver) &&
chosenReceiver.getData() == null &&
!Boolean.TRUE.equals(call.getNodeMetaData(DYNAMIC_RESOLUTION))) {
addStaticTypeError("Non-static method " +
prettyPrintTypeName(declaringClass) + "#" + targetMethodCandidate.getName() + "
cannot be called from static context", call);
} else if (targetMethodCandidate.isAbstract() &&
isSuperExpression(objectExpression)) { // GROOVY-10341
String target =
toMethodParametersString(targetMethodCandidate.getName(),
extractTypesFromParameters(targetMethodCandidate.getParameters()));
diff --git a/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
b/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
index 11bdd7716b..20549ccf13 100644
--- a/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
@@ -1572,6 +1572,13 @@ class MethodCallsSTCTest extends
StaticTypeCheckingTestCase {
'''
}
+ // GROOVY-10939
+ void testClassHashCodeVsObjectHashCode() {
+ assertScript '''
+ int h = this.getClass().hashCode()
+ '''
+ }
+
// GROOVY-10341
void testCallAbstractSuperMethod() {
shouldFailWithMessages '''