check argument types through complete phase
with right data flow info
This commit is contained in:
@@ -350,7 +350,11 @@ public class CandidateResolver {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
JetType type = context.trace.get(BindingContext.EXPRESSION_TYPE, expression);
|
JetType type = context.trace.get(BindingContext.EXPRESSION_TYPE, expression);
|
||||||
|
DataFlowInfo dataFlowInfoForValueArgument = resolvedCall.getDataFlowInfoForValueArgument(argument);
|
||||||
ResolutionContext<?> newContext = context.replaceExpectedType(expectedType);
|
ResolutionContext<?> newContext = context.replaceExpectedType(expectedType);
|
||||||
|
if (dataFlowInfoForValueArgument != null) {
|
||||||
|
newContext = newContext.replaceDataFlowInfo(dataFlowInfoForValueArgument);
|
||||||
|
}
|
||||||
DataFlowUtils.checkType(type, expression, newContext);
|
DataFlowUtils.checkType(type, expression, newContext);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -607,6 +611,7 @@ public class CandidateResolver {
|
|||||||
if (TypeUtils.dependsOnTypeParameters(expectedType, candidateCall.getCandidateDescriptor().getTypeParameters())) {
|
if (TypeUtils.dependsOnTypeParameters(expectedType, candidateCall.getCandidateDescriptor().getTypeParameters())) {
|
||||||
expectedType = NO_EXPECTED_TYPE;
|
expectedType = NO_EXPECTED_TYPE;
|
||||||
}
|
}
|
||||||
|
candidateCall.setDataFlowInfoForArgument(argument, candidateCall.getDataFlowInfo());
|
||||||
CallResolutionContext<?> newContext = context.replaceDataFlowInfo(candidateCall.getDataFlowInfo()).replaceBindingTrace(trace)
|
CallResolutionContext<?> newContext = context.replaceDataFlowInfo(candidateCall.getDataFlowInfo()).replaceBindingTrace(trace)
|
||||||
.replaceExpectedType(expectedType);
|
.replaceExpectedType(expectedType);
|
||||||
JetTypeInfo typeInfoForCall = argumentTypeResolver.getArgumentTypeInfo(
|
JetTypeInfo typeInfoForCall = argumentTypeResolver.getArgumentTypeInfo(
|
||||||
|
|||||||
+10
@@ -76,6 +76,7 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
|
|||||||
private final Map<TypeParameterDescriptor, JetType> typeArguments = Maps.newLinkedHashMap();
|
private final Map<TypeParameterDescriptor, JetType> typeArguments = Maps.newLinkedHashMap();
|
||||||
private final Map<ValueParameterDescriptor, ResolvedValueArgument> valueArguments = Maps.newLinkedHashMap();
|
private final Map<ValueParameterDescriptor, ResolvedValueArgument> valueArguments = Maps.newLinkedHashMap();
|
||||||
private final Set<ValueArgument> unmappedArguments = Sets.newLinkedHashSet();
|
private final Set<ValueArgument> unmappedArguments = Sets.newLinkedHashSet();
|
||||||
|
private final Map<ValueArgument, DataFlowInfo> dataFlowInfoForArguments = Maps.newHashMap();
|
||||||
private boolean someArgumentHasNoType = false;
|
private boolean someArgumentHasNoType = false;
|
||||||
private final DelegatingBindingTrace trace;
|
private final DelegatingBindingTrace trace;
|
||||||
private final TracingStrategy tracing;
|
private final TracingStrategy tracing;
|
||||||
@@ -263,11 +264,20 @@ public class ResolvedCallImpl<D extends CallableDescriptor> implements ResolvedC
|
|||||||
return dataFlowInfo;
|
return dataFlowInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public DataFlowInfo getDataFlowInfoForValueArgument(@NotNull ValueArgument valueArgument) {
|
||||||
|
return dataFlowInfoForArguments.get(valueArgument);
|
||||||
|
}
|
||||||
|
|
||||||
public void setInitialDataFlowInfo(@NotNull DataFlowInfo info) {
|
public void setInitialDataFlowInfo(@NotNull DataFlowInfo info) {
|
||||||
assert dataFlowInfo == null;
|
assert dataFlowInfo == null;
|
||||||
dataFlowInfo = info;
|
dataFlowInfo = info;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDataFlowInfoForArgument(@NotNull ValueArgument valueArgument, @NotNull DataFlowInfo info) {
|
||||||
|
dataFlowInfoForArguments.put(valueArgument, info);
|
||||||
|
}
|
||||||
|
|
||||||
public void addDataFlowInfo(@NotNull DataFlowInfo info) {
|
public void addDataFlowInfo(@NotNull DataFlowInfo info) {
|
||||||
assert dataFlowInfo != null;
|
assert dataFlowInfo != null;
|
||||||
dataFlowInfo = dataFlowInfo.and(info);
|
dataFlowInfo = dataFlowInfo.and(info);
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
package aaa
|
||||||
|
|
||||||
|
fun bar(<!UNUSED_PARAMETER!>a<!>: Int, <!UNUSED_PARAMETER!>b<!>: Int) {}
|
||||||
|
|
||||||
|
fun foo(a: Int?) {
|
||||||
|
bar(a!!, a)
|
||||||
|
}
|
||||||
@@ -5052,6 +5052,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
|||||||
doTest("compiler/testData/diagnostics/tests/smartCasts/combineWithNoSelectorInfo.kt");
|
doTest("compiler/testData/diagnostics/tests/smartCasts/combineWithNoSelectorInfo.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("dataFlowInfoForArguments.kt")
|
||||||
|
public void testDataFlowInfoForArguments() throws Exception {
|
||||||
|
doTest("compiler/testData/diagnostics/tests/smartCasts/dataFlowInfoForArguments.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("kt1461.kt")
|
@TestMetadata("kt1461.kt")
|
||||||
public void testKt1461() throws Exception {
|
public void testKt1461() throws Exception {
|
||||||
doTest("compiler/testData/diagnostics/tests/smartCasts/kt1461.kt");
|
doTest("compiler/testData/diagnostics/tests/smartCasts/kt1461.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user