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 4a502a84e8a..aaec75b59fe 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 @@ -310,7 +310,7 @@ public class CandidateResolver { : effectiveExpectedType; //todo inner calls should be analyzed, for parenthesized, labeled, if, when expressions as well - JetVisitor callExpressionFinder = new JetVisitor() { + JetVisitor selectorExpressionFinder = new JetVisitor() { @Override public JetExpression visitQualifiedExpression(JetQualifiedExpression expression, Void data) { JetExpression selector = expression.getSelectorExpression(); @@ -322,16 +322,31 @@ public class CandidateResolver { return expression; } + @Override + public JetExpression visitSimpleNameExpression(JetSimpleNameExpression expression, Void data) { + return expression; + } + @Override public JetExpression visitJetElement(JetElement element, Void data) { return null; } }; - JetExpression callExpression = expression.accept(callExpressionFinder, null); - if (callExpression == null) continue; + // selector expression is callExpression or simpleNameExpression (if it's inside qualified expression) + JetExpression selectorExpression = expression.accept(selectorExpressionFinder, null); + if (selectorExpression == null) continue; + if (selectorExpression instanceof JetSimpleNameExpression) { + if (expression instanceof JetQualifiedExpression) { + //todo get rid of this hack, 'checkType' once at the end of the analysis + JetType type = context.trace.get(BindingContext.EXPRESSION_TYPE, selectorExpression); + DataFlowUtils.checkType(type, expression, context.replaceExpectedType(expectedType)); + } + continue; + } CallCandidateResolutionContext storedContextForArgument = - context.resolutionResultsCache.getDeferredComputation(CallKey.create(Call.CallType.DEFAULT, callExpression)); + context.resolutionResultsCache.getDeferredComputation(CallKey.create(Call.CallType.DEFAULT, selectorExpression)); + //todo assert storedContextForArgument != null if (storedContextForArgument == null) continue; CallCandidateResolutionContext contextForArgument = diff --git a/compiler/testData/diagnostics/tests/inference/nestedCalls/checkTypesForQualifiedProperties.kt b/compiler/testData/diagnostics/tests/inference/nestedCalls/checkTypesForQualifiedProperties.kt new file mode 100644 index 00000000000..055117ef35d --- /dev/null +++ b/compiler/testData/diagnostics/tests/inference/nestedCalls/checkTypesForQualifiedProperties.kt @@ -0,0 +1,9 @@ +package a + +fun test(c: C) { + foo(c.b) +} + +fun foo(s: String) = s + +class C(val b: Int) {} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java index d9a61f6c701..cc775049764 100644 --- a/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/checkers/JetDiagnosticsTestGenerated.java @@ -2175,6 +2175,11 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), "org.jetbrains.jet.generators.tests.GenerateTests", new File("compiler/testData/diagnostics/tests/inference/nestedCalls"), Pattern.compile("^(.+)\\.kt$"), true); } + @TestMetadata("checkTypesForQualifiedProperties.kt") + public void testCheckTypesForQualifiedProperties() throws Exception { + doTest("compiler/testData/diagnostics/tests/inference/nestedCalls/checkTypesForQualifiedProperties.kt"); + } + @TestMetadata("completeNestedCallsForArraySetExpression.kt") public void testCompleteNestedCallsForArraySetExpression() throws Exception { doTest("compiler/testData/diagnostics/tests/inference/nestedCalls/completeNestedCallsForArraySetExpression.kt");