Introduce synthetic scope for constructors of fun interfaces
#KT-37434 Fixed
This commit is contained in:
@@ -27,6 +27,7 @@ import org.jetbrains.kotlin.resolve.deprecation.DeprecationResolver
|
||||
import org.jetbrains.kotlin.resolve.sam.SamConversionOracle
|
||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScope
|
||||
import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes
|
||||
import org.jetbrains.kotlin.resolve.scopes.synthetic.FunInterfaceConstructorsSyntheticScope
|
||||
import org.jetbrains.kotlin.storage.StorageManager
|
||||
|
||||
class JavaSyntheticScopes(
|
||||
@@ -69,7 +70,10 @@ class JavaSyntheticScopes(
|
||||
)
|
||||
)
|
||||
|
||||
scopes = listOf(javaSyntheticPropertiesScope, samAdapterFunctionsScope) + scopesFromExtensions
|
||||
val funInterfaceConstructorsScopes =
|
||||
FunInterfaceConstructorsSyntheticScope(storageManager, lookupTracker, samConventionResolver, samConversionOracle)
|
||||
|
||||
scopes = listOf(javaSyntheticPropertiesScope, samAdapterFunctionsScope, funInterfaceConstructorsScopes) + scopesFromExtensions
|
||||
|
||||
if (samConversionPerArgumentIsEnabled) {
|
||||
val forceEnabledSamAdapterFunctionsScope = SamAdapterFunctionsScope(
|
||||
|
||||
+4
-4
@@ -29,6 +29,7 @@ import org.jetbrains.kotlin.incremental.record
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassConstructorDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaClassDescriptor
|
||||
import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor
|
||||
import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaClassDescriptor
|
||||
import org.jetbrains.kotlin.load.java.sam.JavaSingleAbstractMethodUtils
|
||||
import org.jetbrains.kotlin.load.java.sam.SamAdapterDescriptor
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
@@ -71,7 +72,7 @@ class SamAdapterFunctionsScope(
|
||||
}
|
||||
|
||||
private val samConstructorForClassifier =
|
||||
storageManager.createMemoizedFunction<ClassDescriptor, SamConstructorDescriptor> { classifier ->
|
||||
storageManager.createMemoizedFunction<JavaClassDescriptor, SamConstructorDescriptor> { classifier ->
|
||||
createSamConstructorFunction(classifier.containingDeclaration, classifier, samResolver, samConversionOracle)
|
||||
}
|
||||
|
||||
@@ -257,15 +258,14 @@ class SamAdapterFunctionsScope(
|
||||
return getTypeAliasSamConstructor(classifier)
|
||||
}
|
||||
|
||||
if (classifier !is ClassDescriptor) return null
|
||||
if (!JavaSingleAbstractMethodUtils.isSamClassDescriptor(classifier)) return null
|
||||
if (classifier !is LazyJavaClassDescriptor || classifier.defaultFunctionTypeForSamInterface == null) return null
|
||||
|
||||
return samConstructorForClassifier(classifier)
|
||||
}
|
||||
|
||||
private fun getTypeAliasSamConstructor(classifier: TypeAliasDescriptor): SamConstructorDescriptor? {
|
||||
val classDescriptor = classifier.classDescriptor ?: return null
|
||||
if (!JavaSingleAbstractMethodUtils.isSamClassDescriptor(classDescriptor)) return null
|
||||
if (classDescriptor !is LazyJavaClassDescriptor || classDescriptor.defaultFunctionTypeForSamInterface == null) return null
|
||||
|
||||
return createTypeAliasSamConstructorFunction(
|
||||
classifier, samConstructorForClassifier(classDescriptor), samResolver, samConversionOracle
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
fun interface Foo<T> {
|
||||
fun invoke(): T
|
||||
}
|
||||
|
||||
fun test() {
|
||||
Foo { }
|
||||
Foo<Unit> { }
|
||||
Foo<String> <!TYPE_MISMATCH!>{ }<!>
|
||||
Foo<String> { "" }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package
|
||||
|
||||
public fun test(): kotlin.Unit
|
||||
|
||||
public fun interface Foo</*0*/ T> {
|
||||
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
|
||||
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
|
||||
public abstract fun invoke(): T
|
||||
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
|
||||
}
|
||||
@@ -10,4 +10,5 @@ fun foo(k: KRunnable) = k.invoke()
|
||||
|
||||
fun test() {
|
||||
foo { "OK" }
|
||||
foo(KRunnable { "OK "})
|
||||
}
|
||||
@@ -10,4 +10,5 @@ fun foo(k: KRunnable) = k.invoke()
|
||||
|
||||
fun test() {
|
||||
foo { "OK" }
|
||||
foo(KRunnable { "OK " })
|
||||
}
|
||||
@@ -10,4 +10,5 @@ fun foo(k: KRunnable) = k.invoke()
|
||||
|
||||
fun test() {
|
||||
foo { "OK" }
|
||||
foo(KRunnable { "OK " })
|
||||
}
|
||||
+5
@@ -28,6 +28,11 @@ public class DiagnosticsTestWithJsStdLibGenerated extends AbstractDiagnosticsTes
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/diagnostics/testsWithJsStdLib"), Pattern.compile("^(.+)\\.kt$"), null, true);
|
||||
}
|
||||
|
||||
@TestMetadata("funConstructorCallJS.kt")
|
||||
public void testFunConstructorCallJS() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithJsStdLib/funConstructorCallJS.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("implementingFunction.kt")
|
||||
public void testImplementingFunction() throws Exception {
|
||||
runTest("compiler/testData/diagnostics/testsWithJsStdLib/implementingFunction.kt");
|
||||
|
||||
Reference in New Issue
Block a user