From 6437a4bdc6ae1b6042e336aefed4ca7d45599dbb Mon Sep 17 00:00:00 2001 From: Dmitry Petrov Date: Tue, 14 Jul 2015 17:53:12 +0300 Subject: [PATCH] Support overload ambiguity resolution for callable references by expected type. Resolve callable references taking into account expected callable types. This affects call resolution procedure (resolve 'foo' in for 'foo(::bar)') similar to the approach used for function literals: * During "shape arguments" phase of call resolution, callable references are resolved in independent context without expected type. If the callable reference is ambiguous, its shape type is a function placeholder type without parameter types and return type information. Otherwise, it is a reflection type for the resolved function or property. Upper-level call is resolved without taking into account ambiguous callable references. * During "complete call" phase of call resolution, resolve callable reference arguments to actual descriptors (if possible), and update constraint system for the given call accordingly. #KT-6982 Fixed #KT-5780 Fixed --- .idea/compiler.xml | 2 + .../CallableReferencesResolutionUtils.kt | 276 ++++++++++++++++++ .../resolve/calls/ArgumentTypeResolver.java | 82 +++++- .../kotlin/resolve/calls/CallCompleter.kt | 17 +- .../resolve/calls/CallExpressionResolver.java | 10 +- .../kotlin/resolve/calls/CallResolver.java | 12 +- .../kotlin/resolve/calls/CallResolverUtil.kt | 31 +- .../kotlin/resolve/calls/CandidateResolver.kt | 47 ++- .../resolve/calls/GenericCandidateResolver.kt | 74 ++++- .../context/BasicCallResolutionContext.java | 8 +- .../CallCandidateResolutionContext.java | 2 +- .../calls/context/CallResolutionContext.java | 6 +- ...sMode.java => CheckArgumentTypesMode.java} | 12 +- .../results/ResolutionResultsHandler.java | 4 +- .../resolve/calls/tasks/ResolutionTask.java | 2 +- .../BasicExpressionTypingVisitor.java | 175 +---------- .../expressions/ExpressionTypingServices.java | 5 + .../function/overloadedFun.kt | 22 ++ .../function/overloadedFunVsVal.kt | 19 ++ .../function/ambiguityTopLevelVsTopLevel.kt | 2 +- .../function/constructorFromCompanion.kt | 22 ++ .../function/constructorFromCompanion.txt | 35 +++ .../returnTypeDependentOnGenericProperty.kt | 8 + .../returnTypeDependentOnGenericProperty.txt | 12 + .../property/syntheticProperties.kt | 19 ++ .../property/syntheticProperties.txt | 13 + .../callableReference/resolve/byArgType.kt | 10 + .../callableReference/resolve/byArgType.txt | 6 + .../resolve/byGenericArgType.kt | 10 + .../resolve/byGenericArgType.txt | 8 + .../callableReference/resolve/byValType.kt | 9 + .../callableReference/resolve/byValType.txt | 8 + .../callableReference/resolve/constructor.kt | 12 + .../callableReference/resolve/constructor.txt | 12 + .../callableReference/resolve/valVsFun.kt | 11 + .../callableReference/resolve/valVsFun.txt | 13 + .../tests/callableReference/resolve/withAs.kt | 10 + .../callableReference/resolve/withAs.txt | 8 + .../callableReference/resolve/withExtFun.kt | 28 ++ .../callableReference/resolve/withExtFun.txt | 25 ++ .../resolve/withGenericFun.kt | 10 + .../resolve/withGenericFun.txt | 8 + .../resolve/withPlaceholderTypes.kt | 26 ++ .../resolve/withPlaceholderTypes.txt | 18 ++ .../callableReference/resolve/withVararg.kt | 10 + .../callableReference/resolve/withVararg.txt | 9 + .../checkers/JetDiagnosticsTestGenerated.java | 87 ++++++ ...lackBoxWithStdlibCodegenTestGenerated.java | 12 + .../kotlin/builtins/ReflectionTypes.kt | 29 ++ .../idea/util/ShadowedDeclarationsFilter.kt | 4 +- .../kotlin/idea/completion/ExpectedInfos.kt | 4 +- 51 files changed, 1057 insertions(+), 247 deletions(-) create mode 100644 compiler/frontend/src/org/jetbrains/kotlin/resolve/callableReferences/CallableReferencesResolutionUtils.kt rename compiler/frontend/src/org/jetbrains/kotlin/resolve/calls/context/{CheckValueArgumentsMode.java => CheckArgumentTypesMode.java} (72%) create mode 100644 compiler/testData/codegen/boxWithStdlib/callableReference/function/overloadedFun.kt create mode 100644 compiler/testData/codegen/boxWithStdlib/callableReference/function/overloadedFunVsVal.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/constructorFromCompanion.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/function/constructorFromCompanion.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/returnTypeDependentOnGenericProperty.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/returnTypeDependentOnGenericProperty.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/property/syntheticProperties.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/byArgType.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/byArgType.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/byGenericArgType.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/byGenericArgType.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/byValType.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/byValType.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/constructor.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/constructor.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/valVsFun.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/valVsFun.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withAs.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withAs.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withExtFun.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withExtFun.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withGenericFun.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withGenericFun.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withPlaceholderTypes.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withPlaceholderTypes.txt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withVararg.kt create mode 100644 compiler/testData/diagnostics/tests/callableReference/resolve/withVararg.txt diff --git a/.idea/compiler.xml b/.idea/compiler.xml index 187598e704d..396faaaaa61 100644 --- a/.idea/compiler.xml +++ b/.idea/compiler.xml @@ -4,7 +4,9 @@