From 0c5eca16d550534326ed51ace92fe20d3957b109 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 5 Jul 2011 16:08:25 +0400 Subject: [PATCH] if (a != null) return a // nullability info considered --- .../jetbrains/jet/lang/types/JetTypeInferrer.java | 14 +++++++++----- idea/testData/checker/Nullability.jet | 6 ++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java b/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java index 2de83a29291..bab31af7a1c 100644 --- a/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java +++ b/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java @@ -539,7 +539,7 @@ public class JetTypeInferrer { if (someNamed) { // TODO : check that all are named - throw new UnsupportedOperationException(); // TODO + trace.getErrorHandler().genericError(call.asElement().getNode(), "Named arguments are not supported"); // TODO // result = overloadDomain.getFunctionDescriptorForNamedArguments(typeArguments, valueArguments, functionLiteralArgument); } else { @@ -1093,7 +1093,10 @@ public class JetTypeInferrer { if (context.expectedReturnType != null && returnedType != null) { if (!semanticServices.getTypeChecker().isSubtypeOf(returnedType, context.expectedReturnType)) { - context.trace.getErrorHandler().typeMismatch(returnedExpression == null ? expression : returnedExpression, context.expectedReturnType, returnedType); + JetType enrichedType = enrichOutType(returnedExpression, returnedType); + if (!semanticServices.getTypeChecker().isSubtypeOf(enrichedType, context.expectedReturnType)) { + context.trace.getErrorHandler().typeMismatch(returnedExpression == null ? expression : returnedExpression, context.expectedReturnType, returnedType); + } } } @@ -2015,12 +2018,13 @@ public class JetTypeInferrer { } } - private JetType enrichOutType(JetExpression receiverExpression, JetType receiverType) { - VariableDescriptor variableDescriptor = getVariableDescriptorFromSimpleName(receiverExpression); + private JetType enrichOutType(JetExpression expression, JetType initialType) { + if (expression == null) return initialType; + VariableDescriptor variableDescriptor = getVariableDescriptorFromSimpleName(expression); if (variableDescriptor != null) { return context.dataFlowInfo.getOutType(variableDescriptor); } - return receiverType; + return initialType; } @Nullable diff --git a/idea/testData/checker/Nullability.jet b/idea/testData/checker/Nullability.jet index 770ed4c746b..8479b364cd8 100644 --- a/idea/testData/checker/Nullability.jet +++ b/idea/testData/checker/Nullability.jet @@ -272,3 +272,9 @@ fun f8(b : String?, a : String) { b.get(0) } } + +fun f9(a : Int?) : Int { + if (a != null) + return a + return 1 +} \ No newline at end of file