Repository: groovy Updated Branches: refs/heads/GROOVY_2_6_X 1f852876d -> abb285ee9
GROOVY-7929: @SelfType compilation fail Project: http://git-wip-us.apache.org/repos/asf/groovy/repo Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/abb285ee Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/abb285ee Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/abb285ee Branch: refs/heads/GROOVY_2_6_X Commit: abb285ee98f81356a4e1b226d38e3c2ce818fce9 Parents: 1f85287 Author: paulk <[email protected]> Authored: Thu Jan 25 13:25:13 2018 +1000 Committer: paulk <[email protected]> Committed: Thu Jan 25 13:26:29 2018 +1000 ---------------------------------------------------------------------- .../transform/stc/TraitTypeCheckingExtension.java | 5 ++--- src/test/groovy/transform/stc/BugsSTCTest.groovy | 18 +++++++++++++++++- 2 files changed, 19 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/groovy/blob/abb285ee/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java b/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java index 1ba75f4..9bc93b5 100644 --- a/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java +++ b/src/main/java/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java @@ -38,9 +38,8 @@ import static org.codehaus.groovy.transform.stc.StaticTypeCheckingSupport.isClas /** * A type checking extension that will take care of handling errors which are specific to traits. In particular, it will - * hanldle the "super" method calls within a trait. + * handle the "super" method calls within a trait. * - * @author Cédric Champeau * @since 2.3.0 */ public class TraitTypeCheckingExtension extends AbstractTypeCheckingExtension { @@ -78,7 +77,7 @@ public class TraitTypeCheckingExtension extends AbstractTypeCheckingExtension { } else if (isThisTraitReceiver(var)) { type = receiver; } - if (type != null && Traits.isTrait(type)) { + if (type != null && Traits.isTrait(type) && !(type instanceof UnionTypeClassNode)) { ClassNode helper = Traits.findHelper(type); Parameter[] params = new Parameter[argumentTypes.length + 1]; params[0] = new Parameter(ClassHelper.CLASS_Type.getPlainNodeReference(), "staticSelf"); http://git-wip-us.apache.org/repos/asf/groovy/blob/abb285ee/src/test/groovy/transform/stc/BugsSTCTest.groovy ---------------------------------------------------------------------- diff --git a/src/test/groovy/transform/stc/BugsSTCTest.groovy b/src/test/groovy/transform/stc/BugsSTCTest.groovy index 3a3df35..ef570c6 100644 --- a/src/test/groovy/transform/stc/BugsSTCTest.groovy +++ b/src/test/groovy/transform/stc/BugsSTCTest.groovy @@ -77,13 +77,29 @@ class BugsSTCTest extends StaticTypeCheckingTestCase { def bar() { foo { it - 2 } } ''', 'Cannot find matching method java.lang.Object#minus(int)' } - void testShouldNotAllowMinusBynUntypedVariable() { + void testShouldNotAllowMinusByUntypedVariable() { shouldFailWithMessages ''' def foo(Closure cls) {} def bar() { foo { 2 - it } } ''', 'Cannot find matching method int#minus(java.lang.Object)' } + // GROOVY-7929 + void testShouldDetectInvalidMethodUseWithinTraitWithCompileStaticAndSelfType() { + shouldFailWithMessages ''' + class C1 { + def c1() { } + } + @groovy.transform.CompileStatic + @groovy.transform.SelfType(C1) + trait TT { + def foo() { + c2() + } + } + ''', 'Cannot find matching method <UnionType:C1+TT>#c2' + } + void testGroovy5444() { assertScript ''' def curr = { System.currentTimeMillis() }
