Use empty list instead of ThrowingList in callable reference resolution

Clients of the call resolution do not expect to see a throwing list in call's
arguments, and it's wrong to make each of them check against the special case
that is the resolution of callable references

Fixes EA-69901
This commit is contained in:
Alexander Udalov
2016-05-30 18:17:38 +03:00
parent e2d6e0cbab
commit d8db769823
5 changed files with 21 additions and 47 deletions
@@ -27,7 +27,6 @@ import org.jetbrains.kotlin.name.Name
import org.jetbrains.kotlin.psi.KtCallableReferenceExpression
import org.jetbrains.kotlin.psi.KtExpression
import org.jetbrains.kotlin.psi.KtSimpleNameExpression
import org.jetbrains.kotlin.psi.ValueArgument
import org.jetbrains.kotlin.resolve.*
import org.jetbrains.kotlin.resolve.calls.CallResolver
import org.jetbrains.kotlin.resolve.calls.callResolverUtil.ResolveArgumentsMode
@@ -51,7 +50,6 @@ import org.jetbrains.kotlin.types.KotlinType
import org.jetbrains.kotlin.types.TypeUtils
import org.jetbrains.kotlin.types.expressions.ExpressionTypingUtils
import org.jetbrains.kotlin.utils.Printer
import org.jetbrains.kotlin.utils.ThrowingList
private fun <D : CallableDescriptor> ResolveArgumentsMode.acceptResolution(results: OverloadResolutionResults<D>, trace: TemporaryTraceAndCache) {
when (this) {
@@ -69,7 +67,7 @@ private fun resolvePossiblyAmbiguousCallableReference(
resolutionMode: ResolveArgumentsMode,
callResolver: CallResolver
): OverloadResolutionResults<CallableDescriptor> {
val call = CallMaker.makeCall(reference, receiver, null, reference, ThrowingList.instance<ValueArgument>())
val call = CallMaker.makeCall(reference, receiver, null, reference, emptyList())
val temporaryTrace = TemporaryTraceAndCache.create(context, "trace to resolve ::${reference.getReferencedName()} as function", reference)
val newContext = if (resolutionMode == ResolveArgumentsMode.SHAPE_FUNCTION_ARGUMENTS)
context.replaceTraceAndCache(temporaryTrace).replaceExpectedType(TypeUtils.NO_EXPECTED_TYPE)
@@ -1,44 +0,0 @@
/*
* Copyright 2010-2015 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.utils;
import org.jetbrains.annotations.NotNull;
import java.util.AbstractList;
public class ThrowingList<E> extends AbstractList<E> {
private static final ThrowingList<?> INSTANCE = new ThrowingList<Object>();
private ThrowingList() {}
@NotNull
@SuppressWarnings("unchecked")
public static <E> ThrowingList<E> instance() {
return (ThrowingList<E>) INSTANCE;
}
@NotNull
@Override
public E get(int index) {
throw new UnsupportedOperationException(getClass().getName());
}
@Override
public int size() {
throw new UnsupportedOperationException(getClass().getName());
}
}
@@ -0,0 +1,5 @@
// !DIAGNOSTICS_NUMBER: 1
// !DIAGNOSTICS: NONE_APPLICABLE
fun filterChars(chars: List<Char>, str: String) =
chars.filter(str::contains)
@@ -0,0 +1,9 @@
<!-- noneApplicableCallableReference1 -->
<html>
None of the following functions can be called with the arguments supplied.
<ul>
<li>CharSequence.contains(<font color=red><b>Char</b></font>, <font color=red><b>Boolean = ...</b></font>) <i>defined in</i> kotlin.text</li>
<li>CharSequence.contains(<font color=red><b>CharSequence</b></font>, <font color=red><b>Boolean = ...</b></font>) <i>defined in</i> kotlin.text</li>
<li>CharSequence.contains(<font color=red><b>Regex</b></font>) <i>defined in</i> kotlin.text</li>
</ul>
</html>
@@ -161,6 +161,12 @@ public class DiagnosticMessageTestGenerated extends AbstractDiagnosticMessageTes
doTest(fileName);
}
@TestMetadata("noneApplicableCallableReference.kt")
public void testNoneApplicableCallableReference() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/diagnosticMessage/noneApplicableCallableReference.kt");
doTest(fileName);
}
@TestMetadata("noneApplicableConstructor.kt")
public void testNoneApplicableConstructor() throws Exception {
String fileName = KotlinTestUtils.navigationMetadata("idea/testData/diagnosticMessage/noneApplicableConstructor.kt");