This is an automated email from the ASF dual-hosted git repository.
emilles pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git
The following commit(s) were added to refs/heads/master by this push:
new 9372f23311 GROOVY-10939: STC: static methods for class except from
`Class`/`Object`
9372f23311 is described below
commit 9372f23311fe711301d18e5036cef44aa388f029
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 1234b8c5bc..52c2c133c5 100644
---
a/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++
b/src/main/java/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -3605,8 +3605,8 @@ out: if (mn.size() != 1) {
if (chosenReceiver == null) {
chosenReceiver =
Receiver.make(declaringClass.getPlainNodeReference());
}
- if (!targetMethod.isStatic() &&
!isClassType(declaringClass) && isClassType(receiver)
- && chosenReceiver.getData() == null &&
call.getNodeMetaData(DYNAMIC_RESOLUTION) == null) {
+ if (!targetMethod.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) + "#" + targetMethod.getName() + " cannot
be called from static context", call);
} else if (targetMethod.isAbstract() &&
isSuperExpression(objectExpression)) { // GROOVY-10341
String target =
toMethodParametersString(targetMethod.getName(),
extractTypesFromParameters(targetMethod.getParameters()));
diff --git a/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
b/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
index 2838725971..5e7602014f 100644
--- a/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
+++ b/src/test/groovy/transform/stc/MethodCallsSTCTest.groovy
@@ -1644,6 +1644,13 @@ class MethodCallsSTCTest extends
StaticTypeCheckingTestCase {
'''
}
+ // GROOVY-10939
+ void testClassHashCodeVsObjectHashCode() {
+ assertScript '''
+ int h = this.getClass().hashCode()
+ '''
+ }
+
// GROOVY-10341
void testCallAbstractSuperMethod() {
shouldFailWithMessages '''