From a717afd9dbb0e98d8e27a07031a26a93120f1962 Mon Sep 17 00:00:00 2001 From: Ilya Ryzhenkov Date: Wed, 12 Aug 2015 13:34:19 +0300 Subject: [PATCH] Fix NPE in checkLValue when selector is absent. Add test for incomplete syntax. --- .../types/expressions/BasicExpressionTypingVisitor.java | 7 +++++-- compiler/testData/diagnostics/tests/LValueAssignment.kt | 5 +++++ compiler/testData/diagnostics/tests/LValueAssignment.txt | 1 + 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java index b35e0ff5d5a..1b94fd0fa9f 100644 --- a/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/kotlin/types/expressions/BasicExpressionTypingVisitor.java @@ -913,8 +913,11 @@ public class BasicExpressionTypingVisitor extends ExpressionTypingVisitor { boolean result = true; JetExpression reportOn = expression != null ? expression : expressionWithParenthesis; - if (reportOn instanceof JetQualifiedExpression) - reportOn = ((JetQualifiedExpression)reportOn).getSelectorExpression(); + if (reportOn instanceof JetQualifiedExpression) { + JetExpression selector = ((JetQualifiedExpression) reportOn).getSelectorExpression(); + if (selector != null) + reportOn = selector; + } if (variable instanceof PropertyDescriptor) { PropertyDescriptor propertyDescriptor = (PropertyDescriptor) variable; diff --git a/compiler/testData/diagnostics/tests/LValueAssignment.kt b/compiler/testData/diagnostics/tests/LValueAssignment.kt index ded49c502fc..1f44d0860ed 100644 --- a/compiler/testData/diagnostics/tests/LValueAssignment.kt +++ b/compiler/testData/diagnostics/tests/LValueAssignment.kt @@ -91,6 +91,11 @@ class Test() { s += (a@ 2) } + fun testIncompleteSyntax() { + val s = "s" + ++s. + } + fun testVariables() { var a: Int = 34 val b: Int = 34 diff --git a/compiler/testData/diagnostics/tests/LValueAssignment.txt b/compiler/testData/diagnostics/tests/LValueAssignment.txt index 4fb69f46e33..6902bf51732 100644 --- a/compiler/testData/diagnostics/tests/LValueAssignment.txt +++ b/compiler/testData/diagnostics/tests/LValueAssignment.txt @@ -67,6 +67,7 @@ package lvalue_assignment { public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int internal final fun testArrays(/*0*/ a: kotlin.Array, /*1*/ ab: lvalue_assignment.Ab): kotlin.Unit internal final fun testIllegalValues(): kotlin.Unit + internal final fun testIncompleteSyntax(): kotlin.Unit internal final fun testVariables(): kotlin.Unit internal final fun testVariables1(): kotlin.Unit public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String