diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java index 38d3e309c9e..59ca5f6be6c 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/BodyResolver.java @@ -194,16 +194,9 @@ public class BodyResolver { } JetExpression delegateExpression = specifier.getDelegateExpression(); if (delegateExpression != null) { - JetScope scope = scopeForConstructor == null - ? scopeForMemberResolution - : scopeForConstructor; - JetType type = typeInferrer.getType(scope, delegateExpression, NO_EXPECTED_TYPE, c.getOuterDataFlowInfo(), trace); - if (type != null && supertype != null) { - SimpleResolutionContext simpleResolutionContext = new SimpleResolutionContext( - trace, scope, supertype, c.getOuterDataFlowInfo(), ContextDependency.INDEPENDENT, - expressionTypingServices.createExtension(scope, false)); - DataFlowUtils.checkType(type, delegateExpression, simpleResolutionContext); - } + JetScope scope = scopeForConstructor == null ? scopeForMemberResolution : scopeForConstructor; + JetType expectedType = supertype != null ? supertype : NO_EXPECTED_TYPE; + typeInferrer.getType(scope, delegateExpression, expectedType, c.getOuterDataFlowInfo(), trace); } } diff --git a/compiler/testData/diagnostics/tests/DelegationAndOverriding.kt b/compiler/testData/diagnostics/tests/delegation/DelegationAndOverriding.kt similarity index 100% rename from compiler/testData/diagnostics/tests/DelegationAndOverriding.kt rename to compiler/testData/diagnostics/tests/delegation/DelegationAndOverriding.kt diff --git a/compiler/testData/diagnostics/tests/delegation/DelegationExpectedType.kt b/compiler/testData/diagnostics/tests/delegation/DelegationExpectedType.kt new file mode 100644 index 00000000000..d795d700bfe --- /dev/null +++ b/compiler/testData/diagnostics/tests/delegation/DelegationExpectedType.kt @@ -0,0 +1,25 @@ +// !DIAGNOSTICS: -UNUSED_PARAMETER + +trait A { + fun foo(): Int +} + +class AImpl: A { + override fun foo() = 42 +} + +class B : A by AImpl() + +fun bar(): A = AImpl() + +class C : A by bar() + +fun baz(f: (T) -> T): A = AImpl() + +class D : A by baz({ it + 1 }) + +fun boo(t: T): A = AImpl() + +class E : A by boo("") + +class F : A by AImpl() \ No newline at end of file diff --git a/compiler/testData/diagnostics/tests/DelegationNotTotrait.kt b/compiler/testData/diagnostics/tests/delegation/DelegationNotTotrait.kt similarity index 100% rename from compiler/testData/diagnostics/tests/DelegationNotTotrait.kt rename to compiler/testData/diagnostics/tests/delegation/DelegationNotTotrait.kt diff --git a/compiler/testData/diagnostics/tests/DelegationToJavaIface.kt b/compiler/testData/diagnostics/tests/delegation/DelegationToJavaIface.kt similarity index 100% rename from compiler/testData/diagnostics/tests/DelegationToJavaIface.kt rename to compiler/testData/diagnostics/tests/delegation/DelegationToJavaIface.kt diff --git a/compiler/testData/diagnostics/tests/Delegation_ClashingFunctions.kt b/compiler/testData/diagnostics/tests/delegation/Delegation_ClashingFunctions.kt similarity index 100% rename from compiler/testData/diagnostics/tests/Delegation_ClashingFunctions.kt rename to compiler/testData/diagnostics/tests/delegation/Delegation_ClashingFunctions.kt diff --git a/compiler/testData/diagnostics/tests/Delegation_Hierarchy.kt b/compiler/testData/diagnostics/tests/delegation/Delegation_Hierarchy.kt similarity index 100% rename from compiler/testData/diagnostics/tests/Delegation_Hierarchy.kt rename to compiler/testData/diagnostics/tests/delegation/Delegation_Hierarchy.kt diff --git a/compiler/testData/diagnostics/tests/Delegation_MultipleDelegates.kt b/compiler/testData/diagnostics/tests/delegation/Delegation_MultipleDelegates.kt similarity index 100% rename from compiler/testData/diagnostics/tests/Delegation_MultipleDelegates.kt rename to compiler/testData/diagnostics/tests/delegation/Delegation_MultipleDelegates.kt diff --git a/compiler/testData/diagnostics/tests/Delegation_ScopeInitializationOrder.kt b/compiler/testData/diagnostics/tests/delegation/Delegation_ScopeInitializationOrder.kt similarity index 100% rename from compiler/testData/diagnostics/tests/Delegation_ScopeInitializationOrder.kt rename to compiler/testData/diagnostics/tests/delegation/Delegation_ScopeInitializationOrder.kt diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 4a9d66511fe..ff37f0c52db 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -30,7 +30,7 @@ import java.util.regex.Pattern; @InnerTestClasses({JetDiagnosticsTestGenerated.Tests.class, JetDiagnosticsTestGenerated.Script.class, JetDiagnosticsTestGenerated.TailRecursion.class, JetDiagnosticsTestGenerated.OnObjects.class}) public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { @TestMetadata("compiler/testData/diagnostics/tests") - @InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ClassObjects.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.CyclicHierarchy.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.DelegatedProperty.class, Tests.Deparenthesize.class, Tests.DuplicateJvmSignature.class, Tests.Enum.class, Tests.Evaluate.class, Tests.Extensions.class, Tests.FunctionLiterals.class, Tests.Generics.class, Tests.Imports.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.Inline.class, Tests.Inner.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Labels.class, Tests.Library.class, Tests.Multimodule.class, Tests.NamedArguments.class, Tests.NullabilityAndAutoCasts.class, Tests.NullableTypes.class, Tests.Numbers.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Recovery.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Resolve.class, Tests.Scopes.class, Tests.SenselessComparison.class, Tests.Shadowing.class, Tests.SmartCasts.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.Suppress.class, Tests.ThisAndSuper.class, Tests.TraitWithRequired.class, Tests.Typedefs.class, Tests.Unit.class, Tests.Varargs.class, Tests.When.class}) + @InnerTestClasses({Tests.Annotations.class, Tests.BackingField.class, Tests.Cast.class, Tests.CheckArguments.class, Tests.ClassObjects.class, Tests.ControlFlowAnalysis.class, Tests.ControlStructures.class, Tests.CyclicHierarchy.class, Tests.DataClasses.class, Tests.DataFlow.class, Tests.DataFlowInfoTraversal.class, Tests.DeclarationChecks.class, Tests.DelegatedProperty.class, Tests.Delegation.class, Tests.Deparenthesize.class, Tests.DuplicateJvmSignature.class, Tests.Enum.class, Tests.Evaluate.class, Tests.Extensions.class, Tests.FunctionLiterals.class, Tests.Generics.class, Tests.Imports.class, Tests.IncompleteCode.class, Tests.Inference.class, Tests.Infos.class, Tests.Inline.class, Tests.Inner.class, Tests.J_k.class, Tests.Jdk_annotations.class, Tests.Labels.class, Tests.Library.class, Tests.Multimodule.class, Tests.NamedArguments.class, Tests.NullabilityAndAutoCasts.class, Tests.NullableTypes.class, Tests.Numbers.class, Tests.Objects.class, Tests.OperatorsOverloading.class, Tests.Overload.class, Tests.Override.class, Tests.Recovery.class, Tests.Redeclarations.class, Tests.Regressions.class, Tests.Resolve.class, Tests.Scopes.class, Tests.SenselessComparison.class, Tests.Shadowing.class, Tests.SmartCasts.class, Tests.Substitutions.class, Tests.Subtyping.class, Tests.Suppress.class, Tests.ThisAndSuper.class, Tests.TraitWithRequired.class, Tests.Typedefs.class, Tests.Unit.class, Tests.Varargs.class, Tests.When.class}) public static class Tests extends AbstractJetDiagnosticsTest { @TestMetadata("Abstract.kt") public void testAbstract() throws Exception { @@ -156,41 +156,6 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { doTest("compiler/testData/diagnostics/tests/DeferredTypes.kt"); } - @TestMetadata("DelegationAndOverriding.kt") - public void testDelegationAndOverriding() throws Exception { - doTest("compiler/testData/diagnostics/tests/DelegationAndOverriding.kt"); - } - - @TestMetadata("DelegationNotTotrait.kt") - public void testDelegationNotTotrait() throws Exception { - doTest("compiler/testData/diagnostics/tests/DelegationNotTotrait.kt"); - } - - @TestMetadata("DelegationToJavaIface.kt") - public void testDelegationToJavaIface() throws Exception { - doTest("compiler/testData/diagnostics/tests/DelegationToJavaIface.kt"); - } - - @TestMetadata("Delegation_ClashingFunctions.kt") - public void testDelegation_ClashingFunctions() throws Exception { - doTest("compiler/testData/diagnostics/tests/Delegation_ClashingFunctions.kt"); - } - - @TestMetadata("Delegation_Hierarchy.kt") - public void testDelegation_Hierarchy() throws Exception { - doTest("compiler/testData/diagnostics/tests/Delegation_Hierarchy.kt"); - } - - @TestMetadata("Delegation_MultipleDelegates.kt") - public void testDelegation_MultipleDelegates() throws Exception { - doTest("compiler/testData/diagnostics/tests/Delegation_MultipleDelegates.kt"); - } - - @TestMetadata("Delegation_ScopeInitializationOrder.kt") - public void testDelegation_ScopeInitializationOrder() throws Exception { - doTest("compiler/testData/diagnostics/tests/Delegation_ScopeInitializationOrder.kt"); - } - @TestMetadata("DiamondFunction.kt") public void testDiamondFunction() throws Exception { doTest("compiler/testData/diagnostics/tests/DiamondFunction.kt"); @@ -2643,6 +2608,54 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { } } + @TestMetadata("compiler/testData/diagnostics/tests/delegation") + public static class Delegation extends AbstractJetDiagnosticsTest { + public void testAllFilesPresentInDelegation() throws Exception { + JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("compiler/testData/diagnostics/tests/delegation"), Pattern.compile("^(.+)\\.kt$"), true); + } + + @TestMetadata("DelegationAndOverriding.kt") + public void testDelegationAndOverriding() throws Exception { + doTest("compiler/testData/diagnostics/tests/delegation/DelegationAndOverriding.kt"); + } + + @TestMetadata("DelegationExpectedType.kt") + public void testDelegationExpectedType() throws Exception { + doTest("compiler/testData/diagnostics/tests/delegation/DelegationExpectedType.kt"); + } + + @TestMetadata("DelegationNotTotrait.kt") + public void testDelegationNotTotrait() throws Exception { + doTest("compiler/testData/diagnostics/tests/delegation/DelegationNotTotrait.kt"); + } + + @TestMetadata("DelegationToJavaIface.kt") + public void testDelegationToJavaIface() throws Exception { + doTest("compiler/testData/diagnostics/tests/delegation/DelegationToJavaIface.kt"); + } + + @TestMetadata("Delegation_ClashingFunctions.kt") + public void testDelegation_ClashingFunctions() throws Exception { + doTest("compiler/testData/diagnostics/tests/delegation/Delegation_ClashingFunctions.kt"); + } + + @TestMetadata("Delegation_Hierarchy.kt") + public void testDelegation_Hierarchy() throws Exception { + doTest("compiler/testData/diagnostics/tests/delegation/Delegation_Hierarchy.kt"); + } + + @TestMetadata("Delegation_MultipleDelegates.kt") + public void testDelegation_MultipleDelegates() throws Exception { + doTest("compiler/testData/diagnostics/tests/delegation/Delegation_MultipleDelegates.kt"); + } + + @TestMetadata("Delegation_ScopeInitializationOrder.kt") + public void testDelegation_ScopeInitializationOrder() throws Exception { + doTest("compiler/testData/diagnostics/tests/delegation/Delegation_ScopeInitializationOrder.kt"); + } + + } + @TestMetadata("compiler/testData/diagnostics/tests/deparenthesize") public static class Deparenthesize extends AbstractJetDiagnosticsTest { public void testAllFilesPresentInDeparenthesize() throws Exception { @@ -8152,6 +8165,7 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest { suite.addTestSuite(DataFlowInfoTraversal.class); suite.addTest(DeclarationChecks.innerSuite()); suite.addTest(DelegatedProperty.innerSuite()); + suite.addTestSuite(Delegation.class); suite.addTestSuite(Deparenthesize.class); suite.addTest(DuplicateJvmSignature.innerSuite()); suite.addTest(Enum.innerSuite());