Repository: groovy Updated Branches: refs/heads/GROOVY_2_4_X 05b366d5f -> 2267a0297
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/2267a029 Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/2267a029 Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/2267a029 Branch: refs/heads/GROOVY_2_4_X Commit: 2267a02972604e9ce4631b280642b88aff96b4f2 Parents: 05b366d Author: paulk <[email protected]> Authored: Thu Jan 25 13:25:13 2018 +1000 Committer: paulk <[email protected]> Committed: Thu Jan 25 13:28:09 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/2267a029/src/main/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java ---------------------------------------------------------------------- diff --git a/src/main/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java b/src/main/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java index 1ba75f4..9bc93b5 100644 --- a/src/main/org/codehaus/groovy/transform/stc/TraitTypeCheckingExtension.java +++ b/src/main/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/2267a029/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 721f11d..41ae357 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() }
