From 2eadd5202d6689872a9d4a6d672ad50796f4a199 Mon Sep 17 00:00:00 2001 From: Svetlana Isakova Date: Fri, 21 Jun 2013 13:54:42 +0400 Subject: [PATCH] check argument types through complete phase with right data flow info --- .../jet/lang/resolve/calls/CandidateResolver.java | 5 +++++ .../jet/lang/resolve/calls/model/ResolvedCallImpl.java | 10 ++++++++++ .../tests/smartCasts/dataFlowInfoForArguments.kt | 7 +++++++ .../jet/checkers/JetDiagnosticsTestGenerated.java | 5 +++++ 4 files changed, 27 insertions(+) create mode 100644 compiler/testData/diagnostics/tests/smartCasts/dataFlowInfoForArguments.kt diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java index a381d431d6e..829e4b38362 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/CandidateResolver.java @@ -350,7 +350,11 @@ public class CandidateResolver { continue; } JetType type = context.trace.get(BindingContext.EXPRESSION_TYPE, expression); + DataFlowInfo dataFlowInfoForValueArgument = resolvedCall.getDataFlowInfoForValueArgument(argument); ResolutionContext newContext = context.replaceExpectedType(expectedType); + if (dataFlowInfoForValueArgument != null) { + newContext = newContext.replaceDataFlowInfo(dataFlowInfoForValueArgument); + } DataFlowUtils.checkType(type, expression, newContext); continue; } @@ -607,6 +611,7 @@ public class CandidateResolver { if (TypeUtils.dependsOnTypeParameters(expectedType, candidateCall.getCandidateDescriptor().getTypeParameters())) { expectedType = NO_EXPECTED_TYPE; } + candidateCall.setDataFlowInfoForArgument(argument, candidateCall.getDataFlowInfo()); CallResolutionContext newContext = context.replaceDataFlowInfo(candidateCall.getDataFlowInfo()).replaceBindingTrace(trace) .replaceExpectedType(expectedType); JetTypeInfo typeInfoForCall = argumentTypeResolver.getArgumentTypeInfo( diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/model/ResolvedCallImpl.java b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/model/ResolvedCallImpl.java index 24b04fc79d4..28ec3b28b52 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/model/ResolvedCallImpl.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/resolve/calls/model/ResolvedCallImpl.java @@ -76,6 +76,7 @@ public class ResolvedCallImpl implements ResolvedC private final Map typeArguments = Maps.newLinkedHashMap(); private final Map valueArguments = Maps.newLinkedHashMap(); private final Set unmappedArguments = Sets.newLinkedHashSet(); + private final Map dataFlowInfoForArguments = Maps.newHashMap(); private boolean someArgumentHasNoType = false; private final DelegatingBindingTrace trace; private final TracingStrategy tracing; @@ -263,11 +264,20 @@ public class ResolvedCallImpl implements ResolvedC return dataFlowInfo; } + @Nullable + public DataFlowInfo getDataFlowInfoForValueArgument(@NotNull ValueArgument valueArgument) { + return dataFlowInfoForArguments.get(valueArgument); + } + public void setInitialDataFlowInfo(@NotNull DataFlowInfo info) { assert dataFlowInfo == null; dataFlowInfo = info; } + public void setDataFlowInfoForArgument(@NotNull ValueArgument valueArgument, @NotNull DataFlowInfo info) { + dataFlowInfoForArguments.put(valueArgument, info); + } + public void addDataFlowInfo(@NotNull DataFlowInfo info) { assert dataFlowInfo != null; dataFlowInfo = dataFlowInfo.and(info); diff --git a/compiler/testData/diagnostics/tests/smartCasts/dataFlowInfoForArguments.kt b/compiler/testData/diagnostics/tests/smartCasts/dataFlowInfoForArguments.kt new file mode 100644 index 00000000000..35f4962f420 --- /dev/null +++ b/compiler/testData/diagnostics/tests/smartCasts/dataFlowInfoForArguments.kt @@ -0,0 +1,7 @@ +package aaa + +fun bar(a: Int, b: Int) {} + +fun foo(a: Int?) { + bar(a!!, a) +} diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index 848f8cc9661..eb2cdc5c7a0 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -5052,6 +5052,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage 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") public void testKt1461() throws Exception { doTest("compiler/testData/diagnostics/tests/smartCasts/kt1461.kt");