From 96cd0d1ae244a9a3ddae50cc3ffee6bb7abbd355 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Mon, 4 Jul 2011 14:34:04 +0400 Subject: [PATCH 1/5] Small fix in nullablilty handling --- grammar/src/notation.grm | 4 ++-- stdlib/src/jet/typeinfo/TypeInfo.java | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/grammar/src/notation.grm b/grammar/src/notation.grm index 94e4316bc21..dc684f42daf 100644 --- a/grammar/src/notation.grm +++ b/grammar/src/notation.grm @@ -21,8 +21,8 @@ alpha{color:blue}*{*{color}beta{color:blue}*}*{color} denotes a nonempty _beta_- h1. Semicolons -*Up* provides "semicolon inference": syntactically, subsentences (e.g., statements, declarations etc) are separated by +[Up] provides "semicolon inference": syntactically, subsentences (e.g., statements, declarations etc) are separated by the pseudo-token [SEMI|#SEMI], which stands for "semicolon or newline". In most cases, there's no need for semicolons in -*Up* code. +[Up] code. */ diff --git a/stdlib/src/jet/typeinfo/TypeInfo.java b/stdlib/src/jet/typeinfo/TypeInfo.java index 3ef38ffc45f..50c5dddff3d 100644 --- a/stdlib/src/jet/typeinfo/TypeInfo.java +++ b/stdlib/src/jet/typeinfo/TypeInfo.java @@ -37,7 +37,7 @@ public class TypeInfo implements JetObject { if (!theClass.isAssignableFrom(other.theClass)) { return false; } - if (nullable != other.nullable) { + if (nullable && !other.nullable) { return false; } if (typeParameters != null) { From b19ad2ccb85b4205d6722cfe9e42cd8c265268b1 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 5 Jul 2011 10:21:45 +0400 Subject: [PATCH 2/5] IO added to Library.jet Header level changed in control.grm --- grammar/src/control.grm | 2 +- idea/src/jet/Library.jet | 24 ++++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/grammar/src/control.grm b/grammar/src/control.grm index 89ea3d6ee54..66091a81b97 100644 --- a/grammar/src/control.grm +++ b/grammar/src/control.grm @@ -1,5 +1,5 @@ /** -h3. Control structures +h2. Control structures bq. See [Control structures] */ diff --git a/idea/src/jet/Library.jet b/idea/src/jet/Library.jet index 2f4673a74d7..04df29fc7ae 100644 --- a/idea/src/jet/Library.jet +++ b/idea/src/jet/Library.jet @@ -7,6 +7,30 @@ namespace typeinfo { } } +namespace io { + fun print(message : Any?) + fun print(message : Int) + fun print(message : Long) + fun print(message : Byte) + fun print(message : Short) + fun print(message : Char) + fun print(message : Boolean) + fun print(message : Float) + fun print(message : Double) + + fun println(message : Any?) + fun println(message : Int) + fun println(message : Long) + fun println(message : Byte) + fun println(message : Short) + fun println(message : Char) + fun println(message : Boolean) + fun println(message : Float) + fun println(message : Double) + + fun readLine() : String? +} + // Can't write a body due to a bootstrapping problem (see JET-74) fun Any?.equals(other : Any?) : Boolean// = this === other From 4121aed7736ffe060ddc85d649897c859160f2dd Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 5 Jul 2011 10:55:33 +0400 Subject: [PATCH 3/5] !is supported in data flow info for ifs --- idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java | 2 +- idea/testData/checker/infos/Autocasts.jet | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java b/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java index e3590f64ca8..2de83a29291 100644 --- a/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java +++ b/idea/src/org/jetbrains/jet/lang/types/JetTypeInferrer.java @@ -1570,7 +1570,7 @@ public class JetTypeInferrer { condition.accept(new JetVisitor() { @Override public void visitIsExpression(JetIsExpression expression) { - if (conditionValue) { + if (conditionValue && !expression.isNegated() || !conditionValue && expression.isNegated()) { JetPattern pattern = expression.getPattern(); result[0] = patternsToDataFlowInfo.get(pattern); if (scopeToExtend != null) { diff --git a/idea/testData/checker/infos/Autocasts.jet b/idea/testData/checker/infos/Autocasts.jet index 8bfdccd7cea..cd930a4f366 100644 --- a/idea/testData/checker/infos/Autocasts.jet +++ b/idea/testData/checker/infos/Autocasts.jet @@ -147,3 +147,9 @@ fun f15(a : A?) { a.bar() c.bar() } + +fun getStringLength(obj : Any) : Char? { + if (obj !is String) + return null + return obj.get(0) // no cast to String is needed +} \ No newline at end of file From 0c5eca16d550534326ed51ace92fe20d3957b109 Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 5 Jul 2011 16:08:25 +0400 Subject: [PATCH 4/5] 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 From 24819c2c95944e685e0fb19791ec77bf03263ebe Mon Sep 17 00:00:00 2001 From: Andrey Breslav Date: Tue, 5 Jul 2011 16:47:12 +0400 Subject: [PATCH 5/5] 'Unsupported' exception replaces with an error --- .../src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java b/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java index e4761ac25b6..48869941b6c 100644 --- a/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java +++ b/idea/src/org/jetbrains/jet/lang/resolve/TopDownAnalyzer.java @@ -275,12 +275,14 @@ public class TopDownAnalyzer { List importDirectives = namespace.getImportDirectives(); for (JetImportDirective importDirective : importDirectives) { if (importDirective.isAbsoluteInRootNamespace()) { - throw new UnsupportedOperationException(); + trace.getErrorHandler().genericError(namespace.getNode(), "Unsupported by TDA"); // TODO + continue; } if (importDirective.isAllUnder()) { JetExpression importedReference = importDirective.getImportedReference(); if (importedReference != null) { - JetType type = semanticServices.getTypeInferrerServices(trace, JetFlowInformationProvider.THROW_EXCEPTION).getTypeWithNamespaces(namespaceScope, importedReference, false); + JetTypeInferrer.Services typeInferrerServices = semanticServices.getTypeInferrerServices(trace, JetFlowInformationProvider.THROW_EXCEPTION); + JetType type = typeInferrerServices.getTypeWithNamespaces(namespaceScope, importedReference, false); if (type != null) { namespaceScope.importScope(type.getMemberScope()); }