mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-176307 Incorrect closure to SAM coercion
This commit is contained in:
+1
-1
@@ -260,7 +260,7 @@ public class SubstitutorComputer {
|
||||
if (closureParameters.length != 1) return null;
|
||||
|
||||
PsiSubstitutor substitutor = myHelper.inferTypeArguments(
|
||||
samClassTypeParameters, new PsiType[]{samReturnType}, closureParameters, LanguageLevel.JDK_1_7
|
||||
samClassTypeParameters, new PsiType[]{samReturnType}, closureParameters, LanguageLevel.JDK_1_8
|
||||
);
|
||||
if (substitutor.getSubstitutionMap().isEmpty()) return null;
|
||||
|
||||
|
||||
+76
@@ -15,7 +15,18 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.lang.highlighting
|
||||
|
||||
import com.intellij.testFramework.LightProjectDescriptor
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.plugins.groovy.GroovyLightProjectDescriptor
|
||||
|
||||
class GrGenericsInferringTest extends GrHighlightingTestBase {
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
protected LightProjectDescriptor getProjectDescriptor() {
|
||||
return GroovyLightProjectDescriptor.GROOVY_2_3
|
||||
}
|
||||
|
||||
void testMapExplicit() {
|
||||
testHighlighting '''
|
||||
import groovy.transform.CompileStatic
|
||||
@@ -319,4 +330,69 @@ class Foo {
|
||||
}
|
||||
'''
|
||||
}
|
||||
|
||||
void testClosureToSAM() {
|
||||
testHighlighting '''\
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
interface SAM<In, Out> {
|
||||
Out run(In argument)
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
class SomeClass2 {
|
||||
static <T> String join(T item, SAM<T, String> f) {
|
||||
return ""
|
||||
}
|
||||
|
||||
static void method() {
|
||||
join(new SomeClass2(), { it.toString() })
|
||||
}
|
||||
}
|
||||
|
||||
'''
|
||||
}
|
||||
|
||||
void testClosureToSAMWildcard() {
|
||||
testHighlighting '''\
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
interface SAM<In, Out> {
|
||||
Out run(In argument)
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
class SomeClass2 {
|
||||
static <T> String join(T item, SAM<? extends T, String> f) {
|
||||
return ""
|
||||
}
|
||||
|
||||
static void method() {
|
||||
join(new SomeClass2(), { it.toString() })
|
||||
}
|
||||
}
|
||||
'''
|
||||
}
|
||||
|
||||
void testClosureToSAMGenericWildcard() {
|
||||
testHighlighting '''\
|
||||
import groovy.transform.CompileStatic
|
||||
|
||||
interface SAM<In, Out> {
|
||||
Out run(In argument)
|
||||
}
|
||||
|
||||
@CompileStatic
|
||||
class SomeClass2 {
|
||||
static <T> String join(List<? extends T> item, SAM<T, String> f) {
|
||||
return ""
|
||||
}
|
||||
|
||||
static void method() {
|
||||
def list = [new SomeClass2()]
|
||||
join(list, { it.toString() })
|
||||
}
|
||||
}
|
||||
'''
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user