diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java index 0c44160a992..3d828b01f86 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetPsiUtil.java @@ -2,6 +2,7 @@ package org.jetbrains.jet.lang.psi; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import org.jetbrains.jet.lexer.JetTokens; import java.util.Collection; import java.util.HashSet; @@ -13,11 +14,25 @@ import java.util.Set; public class JetPsiUtil { @Nullable public static JetExpression deparenthesize(@NotNull JetExpression expression) { - JetExpression result = expression; - while (result instanceof JetParenthesizedExpression) { - result = ((JetParenthesizedExpression) expression).getExpression(); + if (expression instanceof JetBinaryExpressionWithTypeRHS) { + JetSimpleNameExpression operationSign = ((JetBinaryExpressionWithTypeRHS) expression).getOperationSign(); + if (JetTokens.COLON.equals(operationSign.getReferencedNameElementType())) { + expression = ((JetBinaryExpressionWithTypeRHS) expression).getLeft(); + } } - return result; + else if (expression instanceof JetPrefixExpression) { + if (JetTokens.LABELS.contains(((JetPrefixExpression) expression).getOperationSign().getReferencedNameElementType())) { + JetExpression baseExpression = ((JetPrefixExpression) expression).getBaseExpression(); + if (baseExpression != null) { + expression = baseExpression; + } + } + } + if (expression instanceof JetParenthesizedExpression) { + JetExpression innerExpression = ((JetParenthesizedExpression) expression).getExpression(); + return innerExpression != null ? deparenthesize(innerExpression) : null; + } + return expression; } @NotNull diff --git a/compiler/testData/checkerWithErrorTypes/quick/LValueAssignment.jet b/compiler/testData/checkerWithErrorTypes/quick/LValueAssignment.jet index 6702808b0d8..a5e989ec001 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/LValueAssignment.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/LValueAssignment.jet @@ -32,7 +32,27 @@ class D() { } } -fun cannotBe() { +fun cannotBe(var i: Int) { z = 30; () = (); + + (i as Int) = 34 + (i is Int) = false + A() = A() + 5 = 34 +} + +fun canBe(var i: Int, val j: Int) { + (i: Int) = 36 + (@label i) = 34 + + (j: Int) = 36 + (@label j) = 34 + + val a = A() + (@ a.a) = 3894 +} + +class A() { + var a: Int = 3 }