Skip to content

Commit

Permalink
Fix for #815: restore type confidence of private trait method reference
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 19, 2019
1 parent 97cc68b commit 9bd9231
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2018 the original author or authors.
* Copyright 2009-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -91,6 +91,60 @@ public void testPrivateMethod() {
assertExprType(source, "check", "java.lang.Boolean");
}

@Test
public void testPrivateMethod2() {
String contents =
"trait A {\n" +
" private void method() {}\n" +
"}\n" +
"trait B {\n" +
" private void method() {}\n" +
"}\n" +
"class C implements A, B {\n" +
" void something() {\n" +
" method()\n" +
" }\n" +
"}";
assertDeclType(contents, "method", "A");
assertExprType(contents, "method", "java.lang.Void");
}

@Test
public void testPrivateMethod3() {
String contents =
"trait A {\n" +
" private void method() {}\n" +
"}\n" +
"trait B {\n" +
" private void method() {}\n" +
"}\n" +
"class C implements A, B {\n" +
" void something() {\n" +
" A.super.method()\n" +
" }\n" +
"}";
assertDeclType(contents, "method", "A$Trait$Helper");
assertExprType(contents, "method", "java.lang.Void");
}

@Test
public void testPrivateMethod4() {
String contents =
"trait A {\n" +
" private void method() {}\n" +
"}\n" +
"trait B {\n" +
" private void method() {}\n" +
"}\n" +
"class C implements A, B {\n" +
" void something() {\n" +
" B.super.method()\n" +
" }\n" +
"}";
assertDeclType(contents, "method", "B$Trait$Helper");
assertExprType(contents, "method", "java.lang.Void");
}

@Test // https://issues.apache.org/jira/browse/GROOVY-8854
public void testPrivateStaticMethod() {
String source =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -954,7 +954,7 @@ protected static boolean isCompatible(final AnnotatedNode declaration, final boo
}

protected static boolean isNotThisOrOuterClass(final ClassNode thisType, final ClassNode declaringClass) {
return (!thisType.equals(declaringClass) && !thisType.getOuterClasses().contains(declaringClass));
return (!thisType.equals(declaringClass) && !thisType.getOuterClasses().contains(declaringClass) && !(implementsTrait(thisType) && thisType.implementsInterface(declaringClass)));
}

/**
Expand Down

0 comments on commit 9bd9231

Please sign in to comment.