Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix for #1077: T[] and Object[] cannot accept primitive arrays
Browse files Browse the repository at this point in the history
eric-milles committed Apr 9, 2020
1 parent 5c18605 commit 95284b0
Showing 2 changed files with 32 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -587,6 +587,31 @@ public void testDGM45a() {
}
}

@Test
public void testDGM45b() {
String contents =
//@formatter:off
"String[] array = []\n" +
"array.sort { a, b ->\n" +
" a.trim() <=> b.trim()\n" +
"}\n";
//@formatter:on

assertDeclType(contents, "sort", "org.codehaus.groovy.runtime.DefaultGroovyMethods");
}

@Test // https://github.com/groovy/groovy-eclipse/issues/1077
public void testDGM45c() {
String contents =
//@formatter:off
"char[] array = []\n" +
"array.sort()\n";
//@formatter:on

int offset = contents.indexOf("sort");
assertUnknownConfidence(contents, offset, offset + 4);
}

@Test
public void testDGM46() {
String contents =
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2009-2019 the original author or authors.
* Copyright 2009-2020 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.
@@ -397,8 +397,12 @@ private static boolean isAssignable(boolean array, ClassNode source, ClassNode t
} else*/ if (target.isInterface()) {
result = GeneralUtils.isOrImplements(source, target);
} else if (array) {
// Object or Object[] is universal receiver for an array
result = ClassHelper.OBJECT_TYPE.equals(target) || source.isDerivedFrom(target);
if (target.isGenericsPlaceHolder() || target.equals(ClassHelper.OBJECT_TYPE)) {
// T[] or Object[] cannot accept a primitive array
result = !ClassHelper.isPrimitiveType(source);
} else {
result = source.isDerivedFrom(target);
}
} else {
result = getWrapperTypeIfPrimitive(source).isDerivedFrom(getWrapperTypeIfPrimitive(target));
}

0 comments on commit 95284b0

Please sign in to comment.