You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2016/11/06 23:37:28 UTC
groovy git commit: GROOVY-7987: Type checker doesn't flag static
method calls to instance methods with otherwise the same signature (closes
#456)
Repository: groovy
Updated Branches:
refs/heads/master 5714ed7f8 -> 1fa65b4d9
GROOVY-7987: Type checker doesn't flag static method calls to instance methods with otherwise the same signature (closes #456)
Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/1fa65b4d
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/1fa65b4d
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/1fa65b4d
Branch: refs/heads/master
Commit: 1fa65b4d94ad5491f07f62579a52c148e07a41fb
Parents: 5714ed7
Author: paulk <pa...@asert.com.au>
Authored: Wed Nov 2 16:17:25 2016 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Mon Nov 7 09:35:53 2016 +1000
----------------------------------------------------------------------
.../stc/StaticTypeCheckingVisitor.java | 6 +++
src/test/groovy/bugs/Groovy7987Bug.groovy | 40 ++++++++++++++++++++
2 files changed, 46 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/groovy/blob/1fa65b4d/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
index dc8f63d..c21166b 100644
--- a/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
+++ b/src/main/org/codehaus/groovy/transform/stc/StaticTypeCheckingVisitor.java
@@ -2987,6 +2987,12 @@ public class StaticTypeCheckingVisitor extends ClassCodeVisitorSupport {
mn = disambiguateMethods(mn, chosenReceiver!=null?chosenReceiver.getType():null, args, call);
if (mn.size() == 1) {
MethodNode directMethodCallCandidate = mn.get(0);
+ if (call.getNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION) == null &&
+ !directMethodCallCandidate.isStatic() && objectExpression instanceof ClassExpression &&
+ !"java.lang.Class".equals(directMethodCallCandidate.getDeclaringClass().getName())) {
+ ClassNode owner = directMethodCallCandidate.getDeclaringClass();
+ addStaticTypeError("Non static method " + owner.getName() + "#" + directMethodCallCandidate.getName() + " cannot be called from static context", call);
+ }
if (chosenReceiver==null) {
chosenReceiver = Receiver.make(directMethodCallCandidate.getDeclaringClass());
}
http://git-wip-us.apache.org/repos/asf/groovy/blob/1fa65b4d/src/test/groovy/bugs/Groovy7987Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy7987Bug.groovy b/src/test/groovy/bugs/Groovy7987Bug.groovy
new file mode 100644
index 0000000..6d03466
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy7987Bug.groovy
@@ -0,0 +1,40 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package groovy.bugs
+
+import gls.CompilableTestSupport
+
+class Groovy7987Bug extends CompilableTestSupport {
+ void testBindablePropertySettersHaveValidModifiersForMethod() {
+ def message = shouldNotCompile """
+ @groovy.transform.TypeChecked
+ class Foo {
+ def bar() { }
+ }
+
+ @groovy.transform.TypeChecked
+ def method() {
+ Foo.bar()
+ }
+
+ method()
+ """
+ assert message.contains('Non static method Foo#bar cannot be called from static context')
+ }
+}