diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java index dd62dbfd23d..65ba56329d2 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/sam/SingleAbstractMethodUtils.java @@ -20,6 +20,7 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.descriptors.annotations.Annotations; +import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl; import org.jetbrains.kotlin.descriptors.impl.TypeParameterDescriptorImpl; import org.jetbrains.kotlin.descriptors.impl.ValueParameterDescriptorImpl; import org.jetbrains.kotlin.load.java.descriptors.*; @@ -134,28 +135,41 @@ public class SingleAbstractMethodUtils { ) { assert getSingleAbstractMethodOrNull(samInterface) != null : samInterface; - SamConstructorDescriptor result = new SamConstructorDescriptor(owner, samInterface); + SamConstructorDescriptorImpl result = new SamConstructorDescriptorImpl(owner, samInterface); - TypeParameters typeParameters = recreateAndInitializeTypeParameters(samInterface.getTypeConstructor().getParameters(), result); + List samTypeParameters = samInterface.getTypeConstructor().getParameters(); + SimpleType unsubstitutedSamType = samInterface.getDefaultType(); + initializeSamConstructorDescriptor(samInterface, result, samTypeParameters, unsubstitutedSamType); - KotlinType parameterTypeUnsubstituted = getFunctionTypeForSamType(samInterface.getDefaultType()); - assert parameterTypeUnsubstituted != null : "couldn't get function type for SAM type " + samInterface.getDefaultType(); + return result; + } + + private static void initializeSamConstructorDescriptor( + @NotNull JavaClassDescriptor samInterface, + @NotNull SimpleFunctionDescriptorImpl samConstructor, + @NotNull List samTypeParameters, + @NotNull KotlinType unsubstitutedSamType + ) { + TypeParameters typeParameters = recreateAndInitializeTypeParameters(samTypeParameters, samConstructor); + + KotlinType parameterTypeUnsubstituted = getFunctionTypeForSamType(unsubstitutedSamType); + assert parameterTypeUnsubstituted != null : "couldn't get function type for SAM type " + unsubstitutedSamType; KotlinType parameterType = typeParameters.substitutor.substitute(parameterTypeUnsubstituted, Variance.IN_VARIANCE); assert parameterType != null : "couldn't substitute type: " + parameterTypeUnsubstituted + ", substitutor = " + typeParameters.substitutor; ValueParameterDescriptor parameter = new ValueParameterDescriptorImpl( - result, null, 0, Annotations.Companion.getEMPTY(), Name.identifier("function"), parameterType, + samConstructor, null, 0, Annotations.Companion.getEMPTY(), Name.identifier("function"), parameterType, /* declaresDefaultValue = */ false, /* isCrossinline = */ false, /* isNoinline = */ false, /* isCoroutine = */ false, null, SourceElement.NO_SOURCE); - KotlinType returnType = typeParameters.substitutor.substitute(samInterface.getDefaultType(), Variance.OUT_VARIANCE); - assert returnType != null : "couldn't substitute type: " + samInterface.getDefaultType() + + KotlinType returnType = typeParameters.substitutor.substitute(unsubstitutedSamType, Variance.OUT_VARIANCE); + assert returnType != null : "couldn't substitute type: " + unsubstitutedSamType + ", substitutor = " + typeParameters.substitutor; - result.initialize( + samConstructor.initialize( null, null, typeParameters.descriptors, @@ -164,6 +178,18 @@ public class SingleAbstractMethodUtils { Modality.FINAL, samInterface.getVisibility() ); + } + + public static SamConstructorDescriptor createTypeAliasSamConstructorFunction( + @NotNull TypeAliasDescriptor typeAliasDescriptor, + @NotNull SamConstructorDescriptor underlyingSamConstructor + ) { + SamTypeAliasConstructorDescriptorImpl result = new SamTypeAliasConstructorDescriptorImpl(typeAliasDescriptor, underlyingSamConstructor); + + JavaClassDescriptor samInterface = underlyingSamConstructor.getBaseDescriptorForSynthetic(); + List samTypeParameters = typeAliasDescriptor.getTypeConstructor().getParameters(); + SimpleType unsubstitutedSamType = typeAliasDescriptor.getExpandedType(); + initializeSamConstructorDescriptor(samInterface, result, samTypeParameters, unsubstitutedSamType); return result; } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt index 937e7ff2d07..7f92f196deb 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/resolve/jvm/platform/JvmPlatformConfigurator.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.resolve.jvm.JvmOverloadFilter import org.jetbrains.kotlin.resolve.jvm.JvmTypeSpecificityComparator import org.jetbrains.kotlin.resolve.jvm.RuntimeAssertionsTypeChecker import org.jetbrains.kotlin.resolve.jvm.checkers.* +import org.jetbrains.kotlin.synthetic.JavaSyntheticConstructorsProvider import org.jetbrains.kotlin.synthetic.JavaSyntheticScopes import org.jetbrains.kotlin.types.DynamicTypesSettings @@ -81,6 +82,7 @@ object JvmPlatformConfigurator : PlatformConfigurator( container.useImpl() container.useImpl() + container.useInstance(JavaSyntheticConstructorsProvider) container.useInstance(JvmTypeSpecificityComparator) } } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticConstructorsProvider.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticConstructorsProvider.kt new file mode 100644 index 00000000000..f179ed39d7b --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/synthetic/JavaSyntheticConstructorsProvider.kt @@ -0,0 +1,56 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.synthetic + +import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.incremental.components.LookupLocation +import org.jetbrains.kotlin.load.java.descriptors.SamConstructorDescriptorImpl +import org.jetbrains.kotlin.load.java.lazy.descriptors.LazyJavaClassDescriptor +import org.jetbrains.kotlin.load.java.sam.SingleAbstractMethodUtils +import org.jetbrains.kotlin.resolve.scopes.SyntheticConstructorsProvider +import java.lang.AssertionError + +object JavaSyntheticConstructorsProvider : SyntheticConstructorsProvider { + override fun getSyntheticConstructors(classifier: ClassifierDescriptor, location: LookupLocation): Collection { + if (classifier is TypeAliasDescriptor) { + return getSyntheticTypeAliasConstructors(classifier, location) + } + + return emptyList() + } + + private fun getSyntheticTypeAliasConstructors(typeAliasDescriptor: TypeAliasDescriptor, location: LookupLocation): Collection { + val classDescriptor = typeAliasDescriptor.classDescriptor + if (classDescriptor !is LazyJavaClassDescriptor || classDescriptor.functionTypeForSamInterface == null) return emptyList() + + val containingDeclaration = classDescriptor.containingDeclaration + + val outerScope = when (containingDeclaration) { + is ClassDescriptor -> + containingDeclaration.staticScope + is PackageFragmentDescriptor -> + containingDeclaration.getMemberScope() + else -> + throw AssertionError("Unexpected containing declaration for $classDescriptor: $containingDeclaration") + } + + return outerScope.getContributedFunctions(classDescriptor.name, location) + .filterIsInstance() + .filter { it.baseDescriptorForSynthetic == classDescriptor } + .map { SingleAbstractMethodUtils.createTypeAliasSamConstructorFunction(typeAliasDescriptor, it) } + } +} \ No newline at end of file diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt index 8023c7120dc..1cdec00708e 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/TargetPlatform.kt @@ -25,6 +25,7 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.calls.checkers.* import org.jetbrains.kotlin.resolve.calls.results.TypeSpecificityComparator +import org.jetbrains.kotlin.resolve.scopes.SyntheticConstructorsProvider import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.types.DynamicTypesSettings @@ -47,6 +48,7 @@ abstract class TargetPlatform( override fun configure(container: StorageComponentContainer) { super.configure(container) container.useInstance(SyntheticScopes.Empty) + container.useInstance(SyntheticConstructorsProvider.Empty) container.useInstance(TypeSpecificityComparator.NONE) } } diff --git a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt index e5caaf522ae..1e5e2040d58 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt +++ b/compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/tower/NewResolutionOldInference.kt @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.resolve.calls.tower import org.jetbrains.kotlin.descriptors.CallableDescriptor -import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.descriptors.FunctionDescriptor import org.jetbrains.kotlin.descriptors.VariableDescriptor import org.jetbrains.kotlin.diagnostics.Errors @@ -44,17 +43,16 @@ import org.jetbrains.kotlin.resolve.calls.tasks.* import org.jetbrains.kotlin.resolve.isHiddenInResolution import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.MemberScope +import org.jetbrains.kotlin.resolve.scopes.SyntheticConstructorsProvider import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes import org.jetbrains.kotlin.resolve.scopes.receivers.* -import org.jetbrains.kotlin.resolve.scopes.utils.getImplicitReceiversHierarchy import org.jetbrains.kotlin.types.DeferredType import org.jetbrains.kotlin.types.ErrorUtils -import org.jetbrains.kotlin.types.KotlinType import org.jetbrains.kotlin.types.isDynamic -import org.jetbrains.kotlin.types.typeUtil.containsError import org.jetbrains.kotlin.util.OperatorNameConventions import org.jetbrains.kotlin.utils.addToStdlib.check import org.jetbrains.kotlin.utils.sure +import java.lang.IllegalStateException import java.util.* class NewResolutionOldInference( @@ -62,7 +60,8 @@ class NewResolutionOldInference( private val towerResolver: TowerResolver, private val resolutionResultsHandler: ResolutionResultsHandler, private val dynamicCallableDescriptors: DynamicCallableDescriptors, - private val syntheticScopes: SyntheticScopes + private val syntheticScopes: SyntheticScopes, + private val syntheticConstructorsProvider: SyntheticConstructorsProvider ) { sealed class ResolutionKind { @@ -151,7 +150,7 @@ class NewResolutionOldInference( } val dynamicScope = dynamicCallableDescriptors.createDynamicDescriptorScope(context.call, context.scope.ownerDescriptor) - val scopeTower = ImplicitScopeTowerImpl(context, dynamicScope, syntheticScopes, context.call.createLookupLocation()) + val scopeTower = ImplicitScopeTowerImpl(context, dynamicScope, syntheticScopes, syntheticConstructorsProvider, context.call.createLookupLocation()) val processor = kind.createTowerProcessor(this, name, tracing, scopeTower, detailedReceiver, context) @@ -282,6 +281,7 @@ class NewResolutionOldInference( val resolutionContext: ResolutionContext<*>, override val dynamicScope: MemberScope, override val syntheticScopes: SyntheticScopes, + override val syntheticConstructorsProvider: SyntheticConstructorsProvider, override val location: LookupLocation ): ImplicitScopeTower { private val cache = HashMap() diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt index ec79f1c260b..9115f5543c8 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/ImplicitScopeTower.kt @@ -21,6 +21,7 @@ import org.jetbrains.kotlin.incremental.components.LookupLocation import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.scopes.LexicalScope import org.jetbrains.kotlin.resolve.scopes.MemberScope +import org.jetbrains.kotlin.resolve.scopes.SyntheticConstructorsProvider import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes import org.jetbrains.kotlin.resolve.scopes.receivers.ReceiverValueWithSmartCastInfo import org.jetbrains.kotlin.types.KotlinType @@ -34,6 +35,8 @@ interface ImplicitScopeTower { val syntheticScopes: SyntheticScopes + val syntheticConstructorsProvider: SyntheticConstructorsProvider + val location: LookupLocation val isDebuggerContext: Boolean diff --git a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt index 71918e57b0b..0add0ef22c9 100644 --- a/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt +++ b/compiler/resolution/src/org/jetbrains/kotlin/resolve/calls/tower/TowerLevels.kt @@ -161,7 +161,7 @@ internal class QualifierScopeTowerLevel(scopeTower: ImplicitScopeTower, val qual } override fun getFunctions(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?) = qualifier.staticScope - .getContributedFunctionsAndConstructors(name, location).map { + .getContributedFunctionsAndConstructors(name, location, scopeTower.syntheticConstructorsProvider).map { createCandidateDescriptor(it, dispatchReceiver = null) } } @@ -172,7 +172,7 @@ internal open class ScopeBasedTowerLevel protected constructor( private val resolutionScope: ResolutionScope ) : AbstractScopeTowerLevel(scopeTower) { - internal constructor(scopeTower: ImplicitScopeTower, lexicalScope: LexicalScope): this(scopeTower, lexicalScope as ResolutionScope) + internal constructor(scopeTower: ImplicitScopeTower, lexicalScope: LexicalScope) : this(scopeTower, lexicalScope as ResolutionScope) override fun getVariables(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection> = resolutionScope.getContributedVariables(name, location).map { @@ -185,7 +185,7 @@ internal open class ScopeBasedTowerLevel protected constructor( } override fun getFunctions(name: Name, extensionReceiver: ReceiverValueWithSmartCastInfo?): Collection> - = resolutionScope.getContributedFunctionsAndConstructors(name, location).map { + = resolutionScope.getContributedFunctionsAndConstructors(name, location, scopeTower.syntheticConstructorsProvider).map { createCandidateDescriptor(it, dispatchReceiver = null) } } @@ -260,11 +260,17 @@ private fun KotlinType?.getInnerConstructors(name: Name, location: LookupLocatio return classifierDescriptor?.constructors?.filter { it.dispatchReceiverParameter != null } ?: emptyList() } -private fun ResolutionScope.getContributedFunctionsAndConstructors(name: Name, location: LookupLocation): Collection { +private fun ResolutionScope.getContributedFunctionsAndConstructors( + name: Name, + location: LookupLocation, + syntheticConstructorsProvider: SyntheticConstructorsProvider +): Collection { val classifier = getContributedClassifier(name, location) return getContributedFunctions(name, location) + (getClassWithConstructors(classifier)?.constructors?.filter { it.dispatchReceiverParameter == null } ?: emptyList()) + - (classifier?.getTypeAliasConstructors()?.filter { it.dispatchReceiverParameter == null } ?: emptyList()) + (classifier?.getTypeAliasConstructors()?.filter { it.dispatchReceiverParameter == null } ?: emptyList()) + + (classifier?.let { syntheticConstructorsProvider.getSyntheticConstructors(it, location) } + ?.filter { it.dispatchReceiverParameter == null } ?: emptyList()) } private fun ResolutionScope.getContributedObjectVariables(name: Name, location: LookupLocation): Collection { diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.kt b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.kt new file mode 100644 index 00000000000..a5e4f8db692 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.kt @@ -0,0 +1,8 @@ +// FILE: test.kt +typealias RunnableT = java.lang.Runnable +typealias ComparatorT = java.util.Comparator +typealias ComparatorStrT = ComparatorT + +val test1 = RunnableT { } +val test2 = ComparatorT { s1, s2 -> s1.compareTo(s2) } +val test3 = ComparatorStrT { s1, s2 -> s1.compareTo(s2) } diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.txt b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.txt new file mode 100644 index 00000000000..9526c3fc591 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.txt @@ -0,0 +1,8 @@ +package + +public val test1: java.lang.Runnable +public val test2: java.util.Comparator +public val test3: ComparatorT /* = java.util.Comparator */ +public typealias ComparatorStrT = ComparatorT +public typealias ComparatorT = java.util.Comparator +public typealias RunnableT = java.lang.Runnable diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.kt b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.kt new file mode 100644 index 00000000000..1fc32ad0417 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.kt @@ -0,0 +1,27 @@ +// FILE: JHost.java +public class JHost { + public static interface Runnable { + void run(); + } + + public static interface Consumer { + void consume(T x); + } + + public static interface Consumer2 { + void run(T1 x1, T2 x2); + } +} + +// FILE: test.kt +typealias R = JHost.Runnable +typealias C = JHost.Consumer +typealias CStr = JHost.Consumer +typealias CStrList = JHost.Consumer> +typealias C2 = JHost.Consumer2 + +val test1 = R { } +val test2 = C { s -> println(s.length) } +val test3 = CStr { s -> println(s.length) } +val test4 = CStrList { ss -> for (s in ss) { println(s.length) } } +val test5 = C2 { a, b -> val x: Int = a + b; println(x)} diff --git a/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.txt b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.txt new file mode 100644 index 00000000000..a18b8cfbbb6 --- /dev/null +++ b/compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.txt @@ -0,0 +1,45 @@ +package + +public val test1: JHost.Runnable +public val test2: JHost.Consumer +public val test3: JHost.Consumer +public val test4: JHost.Consumer> +public val test5: JHost.Consumer2 + +public open class JHost { + public constructor JHost() + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + + public interface Consumer { + public abstract fun consume(/*0*/ x: T!): kotlin.Unit + 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 open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public interface Consumer2 { + 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 run(/*0*/ x1: T1!, /*1*/ x2: T2!): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + public interface Runnable { + 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 run(): kotlin.Unit + public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String + } + + // Static members + public final /*synthesized*/ fun Consumer(/*0*/ function: (T!) -> kotlin.Unit): JHost.Consumer + public final /*synthesized*/ fun Consumer2(/*0*/ function: (T1!, T2!) -> kotlin.Unit): JHost.Consumer2 + public final /*synthesized*/ fun Runnable(/*0*/ function: () -> kotlin.Unit): JHost.Runnable +} +public typealias C = JHost.Consumer +public typealias C2 = JHost.Consumer2 +public typealias CStr = JHost.Consumer +public typealias CStrList = JHost.Consumer> +public typealias R = JHost.Runnable diff --git a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java index 7ccd4a02a00..a83d2ad474e 100644 --- a/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java +++ b/compiler/tests/org/jetbrains/kotlin/checkers/DiagnosticsTestWithStdLibGenerated.java @@ -1250,6 +1250,27 @@ public class DiagnosticsTestWithStdLibGenerated extends AbstractDiagnosticsTestW } } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/typealias") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class Typealias extends AbstractDiagnosticsTestWithStdLib { + public void testAllFilesPresentInTypealias() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/testsWithStdLib/typealias"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("typeAliasSamAdapterConstructors.kt") + public void testTypeAliasSamAdapterConstructors() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors.kt"); + doTest(fileName); + } + + @TestMetadata("typeAliasSamAdapterConstructors2.kt") + public void testTypeAliasSamAdapterConstructors2() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("compiler/testData/diagnostics/testsWithStdLib/typealias/typeAliasSamAdapterConstructors2.kt"); + doTest(fileName); + } + } + @TestMetadata("compiler/testData/diagnostics/testsWithStdLib/varargs") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamConstructorDescriptor.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamConstructorDescriptor.kt index fc04321d8b0..29c967db776 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamConstructorDescriptor.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamConstructorDescriptor.kt @@ -18,11 +18,14 @@ package org.jetbrains.kotlin.load.java.descriptors import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor import org.jetbrains.kotlin.descriptors.DeclarationDescriptor +import org.jetbrains.kotlin.descriptors.SimpleFunctionDescriptor import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl import org.jetbrains.kotlin.descriptors.synthetic.SyntheticMemberDescriptor import org.jetbrains.kotlin.resolve.scopes.DescriptorKindExclude -class SamConstructorDescriptor( +interface SamConstructorDescriptor : SimpleFunctionDescriptor, SyntheticMemberDescriptor + +class SamConstructorDescriptorImpl( containingDeclaration: DeclarationDescriptor, private val samInterface: JavaClassDescriptor ) : SimpleFunctionDescriptorImpl( @@ -32,7 +35,7 @@ class SamConstructorDescriptor( samInterface.name, CallableMemberDescriptor.Kind.SYNTHESIZED, samInterface.source -), SyntheticMemberDescriptor { +), SamConstructorDescriptor { override val baseDescriptorForSynthetic: JavaClassDescriptor get() = samInterface } diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamTypeAliasConstructorDescriptor.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamTypeAliasConstructorDescriptor.kt new file mode 100644 index 00000000000..1d009f2f9f2 --- /dev/null +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/descriptors/SamTypeAliasConstructorDescriptor.kt @@ -0,0 +1,40 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.load.java.descriptors + +import org.jetbrains.kotlin.descriptors.CallableMemberDescriptor +import org.jetbrains.kotlin.descriptors.TypeAliasDescriptor +import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl + +interface SamTypeAliasConstructorDescriptor : SamConstructorDescriptor { + val typeAliasDescriptor: TypeAliasDescriptor +} + +class SamTypeAliasConstructorDescriptorImpl( + override val typeAliasDescriptor: TypeAliasDescriptor, + private val samInterfaceConstructorDescriptor: SamConstructorDescriptor +) : SimpleFunctionDescriptorImpl( + typeAliasDescriptor.containingDeclaration, + null, + samInterfaceConstructorDescriptor.baseDescriptorForSynthetic.annotations, + samInterfaceConstructorDescriptor.baseDescriptorForSynthetic.name, + CallableMemberDescriptor.Kind.SYNTHESIZED, + typeAliasDescriptor.source +), SamTypeAliasConstructorDescriptor { + override val baseDescriptorForSynthetic: JavaClassDescriptor + get() = samInterfaceConstructorDescriptor.baseDescriptorForSynthetic +} \ No newline at end of file diff --git a/core/descriptors/src/org/jetbrains/kotlin/descriptors/TypeAliasDescriptor.kt b/core/descriptors/src/org/jetbrains/kotlin/descriptors/TypeAliasDescriptor.kt index 9c784176957..241b16e6530 100644 --- a/core/descriptors/src/org/jetbrains/kotlin/descriptors/TypeAliasDescriptor.kt +++ b/core/descriptors/src/org/jetbrains/kotlin/descriptors/TypeAliasDescriptor.kt @@ -20,8 +20,12 @@ import org.jetbrains.kotlin.types.SimpleType import org.jetbrains.kotlin.types.TypeSubstitutor interface TypeAliasDescriptor : ClassifierDescriptorWithTypeParameters, MemberDescriptor { + /// Right-hand side of the type alias definition. + /// May contain type aliases. val underlyingType: SimpleType + /// Fully expanded type with non-substituted type parameters. + /// May not contain type aliases. val expandedType: SimpleType val classDescriptor: ClassDescriptor? diff --git a/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SyntheticConstructorsProvider.kt b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SyntheticConstructorsProvider.kt new file mode 100644 index 00000000000..300ba40c231 --- /dev/null +++ b/core/descriptors/src/org/jetbrains/kotlin/resolve/scopes/SyntheticConstructorsProvider.kt @@ -0,0 +1,30 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.resolve.scopes + +import org.jetbrains.kotlin.descriptors.ClassifierDescriptor +import org.jetbrains.kotlin.descriptors.FunctionDescriptor +import org.jetbrains.kotlin.incremental.components.LookupLocation + +interface SyntheticConstructorsProvider { + fun getSyntheticConstructors(classifier: ClassifierDescriptor, location: LookupLocation): Collection + + object Empty : SyntheticConstructorsProvider { + override fun getSyntheticConstructors(classifier: ClassifierDescriptor, location: LookupLocation): Collection = + emptyList() + } +} \ No newline at end of file diff --git a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatformConfigurator.kt b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatformConfigurator.kt index cab14bf3cec..6cd126a4af4 100644 --- a/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatformConfigurator.kt +++ b/js/js.frontend/src/org/jetbrains/kotlin/js/resolve/JsPlatformConfigurator.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.js.resolve.diagnostics.NativeInnerClassChecker import org.jetbrains.kotlin.resolve.IdentifierChecker import org.jetbrains.kotlin.resolve.OverloadFilter import org.jetbrains.kotlin.resolve.PlatformConfigurator +import org.jetbrains.kotlin.resolve.scopes.SyntheticConstructorsProvider import org.jetbrains.kotlin.resolve.scopes.SyntheticScopes import org.jetbrains.kotlin.types.DynamicTypesAllowed @@ -43,6 +44,7 @@ object JsPlatformConfigurator : PlatformConfigurator( container.useImpl() container.useInstance(SyntheticScopes.Empty) + container.useInstance(SyntheticConstructorsProvider.Empty) container.useInstance(JsTypeSpecificityComparator) } }