Skip to content

Commit

Permalink
Fix for issue #468: record type reference for coercion expression "as T"
Browse files Browse the repository at this point in the history
  • Loading branch information
eric-milles committed Feb 13, 2018
1 parent 6d13099 commit 431e885
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,31 @@ public void testShouldntFindClassDeclarationInScript() throws Exception {
assertEquals("Should find no matches", 0, matches.size());
}

@Test // https://github.com/groovy/groovy-eclipse/issues/468
public void testCoercion1() throws Exception {
String firstContents =
"package a\n" +
"interface First {\n" +
" void meth();\n" +
"}\n";

String secondContents =
"package a\n" +
"class Second {\n" +
" def m() {\n" +
" return {->\n" +
" } as First\n" +
" }\n" +
"}\n";

List<SearchMatch> matches = getAllMatches(firstContents, secondContents, "a", "a", false);
assertEquals("Wrong count", 1, matches.size());

SearchMatch match = matches.get(0);
assertEquals("Wrong length", "First".length(), match.getLength());
assertEquals("Wrong offset", secondContents.indexOf("First"), match.getOffset());
}

@Test // https://github.com/groovy/groovy-eclipse/issues/442
public void testGenerics1() throws Exception {
String firstContents =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ public void visitArrayExpression(ArrayExpression expression) {
@Override
public void visitCastExpression(CastExpression expression) {
// NOTE: expression.getType() may refer to ClassNode behind "this" or "super"
if (expression.getEnd() > 0 && expression.getStart() == expression.getType().getStart()) {
if (expression.getEnd() > 0 && (/*cast:*/expression.getStart() == expression.getType().getStart() ||
/*coerce:*/expression.getEnd() == expression.getType().getEnd())) {
visitTypeReference(expression.getType(), false, true);
}
super.visitCastExpression(expression);
Expand Down

0 comments on commit 431e885

Please sign in to comment.