diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java index e69555a882b..923a503c6d4 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/ExpressionCodegen.java @@ -2656,30 +2656,6 @@ If finally block is present, its last expression is the value of try expression. conditionValue = generatePatternMatch(pattern, patternCondition.isNegated(), StackValue.local(subjectLocal, subjectType), nextEntry); } - else if (condition instanceof JetWhenConditionCall) { - final JetExpression call = ((JetWhenConditionCall) condition).getCallSuffixExpression(); - if (call instanceof JetCallExpression) { - v.load(subjectLocal, subjectType); - final DeclarationDescriptor declarationDescriptor = resolveCalleeDescriptor((JetCallExpression) call); - if (!(declarationDescriptor instanceof FunctionDescriptor)) { - throw new UnsupportedOperationException("expected function descriptor in when condition with call, found " + declarationDescriptor); - } - conditionValue = invokeFunction((JetCallExpression) call, declarationDescriptor, StackValue.onStack(subjectType)); - } - else if (call instanceof JetSimpleNameExpression) { - final DeclarationDescriptor descriptor = bindingContext.get(BindingContext.REFERENCE_TARGET, (JetSimpleNameExpression) call); - if (descriptor instanceof PropertyDescriptor) { - v.load(subjectLocal, subjectType); - conditionValue = intermediateValueForProperty((PropertyDescriptor) descriptor, false, null); - } - else { - throw new UnsupportedOperationException("unknown simple name resolve result: " + descriptor); - } - } - else { - throw new UnsupportedOperationException("unsupported kind of call suffix"); - } - } else { throw new UnsupportedOperationException("unsupported kind of when condition"); } diff --git a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java index 3f7fe8350e5..0f694b7e8e5 100644 --- a/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java +++ b/compiler/frontend/src/org/jetbrains/jet/JetNodeTypes.java @@ -141,7 +141,6 @@ public interface JetNodeTypes { JetNodeType WHEN_CONDITION_IN_RANGE = new JetNodeType("WHEN_CONDITION_IN_RANGE", JetWhenConditionInRange.class); JetNodeType WHEN_CONDITION_IS_PATTERN = new JetNodeType("WHEN_CONDITION_IS_PATTERN", JetWhenConditionIsPattern.class); - JetNodeType WHEN_CONDITION_CALL = new JetNodeType("WHEN_CONDITION_CALL", JetWhenConditionCall.class); JetNodeType NAMESPACE_NAME = new JetNodeType("NAMESPACE_NAME", JetContainerNode.class); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java index bb1624eda0d..f5bc5122eda 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/cfg/JetControlFlowProcessor.java @@ -62,10 +62,6 @@ public class JetControlFlowProcessor { private class CFPVisitor extends JetVisitorVoid { private final boolean inCondition; private final JetVisitorVoid conditionVisitor = new JetVisitorVoid() { - @Override - public void visitWhenConditionCall(JetWhenConditionCall condition) { - value(condition.getCallSuffixExpression(), CFPVisitor.this.inCondition); // TODO : inCondition? - } @Override public void visitWhenConditionInRange(JetWhenConditionInRange condition) { diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java index d5b8b5a8760..aa9843843da 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/parsing/JetExpressionParsing.java @@ -419,7 +419,10 @@ public class JetExpressionParsing extends AbstractJetParsing { } else return false; } - else return false; + else { + return false; + } + return true; } @@ -764,7 +767,6 @@ public class JetExpressionParsing extends AbstractJetParsing { /* * whenCondition * : expression - * : ("." | "?." postfixExpression typeArguments? valueArguments? * : ("in" | "!in") expression * : ("is" | "!is") isRHS * ; @@ -793,21 +795,10 @@ public class JetExpressionParsing extends AbstractJetParsing { parsePattern(); } condition.done(WHEN_CONDITION_IS_PATTERN); - } else if (at(DOT) || at(SAFE_ACCESS)) { - advance(); // DOT or SAFE_ACCESS - PsiBuilder.Marker mark = mark(); - parsePostfixExpression(); - if (parseCallSuffix()) { - mark.done(CALL_EXPRESSION); - } - else { - mark.drop(); - } - condition.done(WHEN_CONDITION_CALL); } else { PsiBuilder.Marker expressionPattern = mark(); if (atSet(WHEN_CONDITION_RECOVERY_SET_WITH_DOUBLE_ARROW)) { - error("Expecting an element, is-condition or in-condition"); + error("Expecting an expression, is-condition or in-condition"); } else { parseExpression(); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java index 7b62fcac518..d75649d31e8 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitor.java @@ -356,10 +356,6 @@ public class JetVisitor extends PsiElementVisitor { return visitExpression(expression, data); } - public R visitWhenConditionCall(JetWhenConditionCall condition, D data) { - return visitJetElement(condition, data); - } - public R visitWhenConditionIsPattern(JetWhenConditionIsPattern condition, D data) { return visitJetElement(condition, data); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java index 0f649207239..f3b7fde8385 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetVisitorVoid.java @@ -354,10 +354,6 @@ public class JetVisitorVoid extends PsiElementVisitor { visitExpression(expression); } - public void visitWhenConditionCall(JetWhenConditionCall condition) { - visitJetElement(condition); - } - public void visitWhenConditionIsPattern(JetWhenConditionIsPattern condition) { visitJetElement(condition); } diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetWhenConditionCall.java b/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetWhenConditionCall.java deleted file mode 100644 index c74e0ea6acb..00000000000 --- a/compiler/frontend/src/org/jetbrains/jet/lang/psi/JetWhenConditionCall.java +++ /dev/null @@ -1,40 +0,0 @@ -package org.jetbrains.jet.lang.psi; - -import com.intellij.lang.ASTNode; -import com.intellij.psi.tree.TokenSet; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lexer.JetTokens; - -/** - * @author abreslav - */ -public class JetWhenConditionCall extends JetWhenCondition { - public JetWhenConditionCall(@NotNull ASTNode node) { - super(node); - } - - public boolean isSafeCall() { - return getNode().findChildByType(JetTokens.SAFE_ACCESS) != null; - } - - @NotNull - public ASTNode getOperationTokenNode() { - return getNode().findChildByType(TokenSet.create(JetTokens.SAFE_ACCESS, JetTokens.DOT)); - } - - @Nullable @IfNotParsed - public JetExpression getCallSuffixExpression() { - return findChildByClass(JetExpression.class); - } - - @Override - public void accept(@NotNull JetVisitorVoid visitor) { - visitor.visitWhenConditionCall(this); - } - - @Override - public R accept(@NotNull JetVisitor visitor, D data) { - return visitor.visitWhenConditionCall(this, data); - } -} diff --git a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java index 3753726ce0c..f5c277970bb 100644 --- a/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java +++ b/compiler/frontend/src/org/jetbrains/jet/lang/types/expressions/PatternMatchingTypingVisitor.java @@ -1,12 +1,10 @@ package org.jetbrains.jet.lang.types.expressions; -import com.google.common.collect.Multimap; import com.google.common.collect.Sets; import com.intellij.lang.ASTNode; import com.intellij.openapi.util.Ref; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import org.jetbrains.jet.lang.descriptors.TypeParameterDescriptor; import org.jetbrains.jet.lang.descriptors.VariableDescriptor; import org.jetbrains.jet.lang.diagnostics.Errors; import org.jetbrains.jet.lang.psi.*; @@ -115,19 +113,6 @@ public class PatternMatchingTypingVisitor extends ExpressionTypingVisitor { final DataFlowInfo[] newDataFlowInfo = new DataFlowInfo[]{context.dataFlowInfo}; condition.accept(new JetVisitorVoid() { - @Override - public void visitWhenConditionCall(JetWhenConditionCall condition) { - JetExpression callSuffixExpression = condition.getCallSuffixExpression(); -// JetScope compositeScope = new ScopeWithReceiver(context.scope, subjectType, semanticServices.getTypeChecker()); - if (callSuffixExpression != null) { -// JetType selectorReturnType = getType(compositeScope, callSuffixExpression, false, context); - assert subjectExpression != null; - JetType selectorReturnType = facade.getSelectorReturnType(new ExpressionReceiver(subjectExpression, subjectType), condition.getOperationTokenNode(), callSuffixExpression, context);//getType(compositeScope, callSuffixExpression, false, context); - ensureBooleanResultWithCustomSubject(callSuffixExpression, selectorReturnType, "This expression", context); -// context.getServices().checkNullSafety(subjectType, condition.getOperationTokenNode(), getCalleeFunctionDescriptor(callSuffixExpression, context), condition); - } - } - @Override public void visitWhenConditionInRange(JetWhenConditionInRange condition) { JetExpression rangeExpression = condition.getRangeExpression(); diff --git a/compiler/testData/checkerWithErrorTypes/full/When.jet b/compiler/testData/checkerWithErrorTypes/full/When.jet index 7f53fb38c9d..bff65aac380 100644 --- a/compiler/testData/checkerWithErrorTypes/full/When.jet +++ b/compiler/testData/checkerWithErrorTypes/full/When.jet @@ -13,16 +13,19 @@ fun foo() : Int { 1 + a => 1 in 1..a => 1 !in 1..a => 1 - .a => 1 - .equals(1).a => 1 - ?.equals(1) => 1 + // Commented for KT-621 .a => 1 + // Commented for KT-621 .equals(1).a => 1 + // Commented for KT-621 ?.equals(1) => 1 else => 1 } - return when (x?:null) { - .foo() => 1 - .equals(1) => 1 - ?.equals(1).equals(2) => 1 - } + + // Commented for KT-621 + // return when (x?:null) { + // .foo() => 1 + // .equals(1) => 1 + // ?.equals(1).equals(2) => 1 + // } + return 0 } val _type_test : Int = foo() // this is needed to ensure the inferred return type of foo() diff --git a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt127.jet b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt127.jet index 7bcb076f08c..19ad92b2d52 100644 --- a/compiler/testData/checkerWithErrorTypes/quick/regressions/kt127.jet +++ b/compiler/testData/checkerWithErrorTypes/quick/regressions/kt127.jet @@ -8,8 +8,11 @@ fun Any?.equals1(other : Any?) : Boolean = true fun main(args: Array) { val command : Foo? = null - when (command) { - .equals(null) => 1; // must be resolved - ?.equals(null) => 1 // same here - } + + // Commented for KT-621 + // when (command) { + // .equals(null) => 1; // must be resolved + // ?.equals(null) => 1 // same here + // } + command.equals(null) } diff --git a/compiler/testData/codegen/patternMatching/callProperty.jet b/compiler/testData/codegen/patternMatching/callProperty.jet index b52ac44de96..65fc9b7997d 100644 --- a/compiler/testData/codegen/patternMatching/callProperty.jet +++ b/compiler/testData/codegen/patternMatching/callProperty.jet @@ -2,8 +2,11 @@ class C(val p: Boolean) { } fun box(): String { val c = C(true) - return when(c) { - .p => "OK" - else => "fail" - } + + // Commented for KT-621 + // return when(c) { + // .p => "OK" + // else => "fail" + // } + return if (c.p) "OK" else "fail" } diff --git a/compiler/testData/codegen/regressions/kt528.kt b/compiler/testData/codegen/regressions/kt528.kt index 456f55d04be..8cfe1707aee 100644 --- a/compiler/testData/codegen/regressions/kt528.kt +++ b/compiler/testData/codegen/regressions/kt528.kt @@ -25,14 +25,25 @@ class Luhny() { fun charIn(it : Char) { buffer.addLast(it) - when (it) { - .isDigit() => digits.addLast(it.int - '0'.int) - ' ', '-' => {} - else => { - printAll() - digits.clear() - } + + // Commented for KT-621 + // when (it) { + // .isDigit() => digits.addLast(it.int - '0'.int) + // ' ', '-' => {} + // else => { + // printAll() + // digits.clear() + // } + // } + + if (it.isDigit()) { + digits.addLast(it.int - '0'.int) + } else if (it == ' ' || it == '-') { + } else { + printAll() + digits.clear() } + if (digits.size() > 16) printOneDigit() check() diff --git a/compiler/testData/codegen/regressions/kt529.kt b/compiler/testData/codegen/regressions/kt529.kt index 66487f37509..84a6d3edc52 100644 --- a/compiler/testData/codegen/regressions/kt529.kt +++ b/compiler/testData/codegen/regressions/kt529.kt @@ -23,11 +23,21 @@ class Luhny() { fun process(it : Char) { buffer.addLast(it) - when (it) { - .isDigit() => digits.addLast(it.int - '0'.int) - ' ', '-' => {} - else => printAll() + + // Commented for KT-621 + // when (it) { + // .isDigit() => digits.addLast(it.int - '0'.int) + // ' ', '-' => {} + // else => printAll() + // } + + if (it.isDigit()) { + digits.addLast(it.int - '0'.int) + } else if (it == ' ' || it == '-') { + } else { + printAll() } + if (digits.size() > 16) printOneDigit() check() diff --git a/compiler/testData/codegen/regressions/kt533.kt b/compiler/testData/codegen/regressions/kt533.kt index 05e55878b81..7e7ef961ffd 100644 --- a/compiler/testData/codegen/regressions/kt533.kt +++ b/compiler/testData/codegen/regressions/kt533.kt @@ -24,14 +24,25 @@ class Luhny() { fun charIn(it : Char) { buffer.push(it) - when (it) { - .isDigit() => digits.push(it.int - '0'.int) - ' ', '-' => {} - else => { - printAll() - digits.clear() - } + + // Commented for KT-621 + // when (it) { + // .isDigit() => digits.push(it.int - '0'.int) + // ' ', '-' => {} + // else => { + // printAll() + // digits.clear() + // } + // } + + if (it.isDigit()) { + digits.push(it.int - '0'.int) + } else if (it == ' ' || it == '-') { + } else { + printAll() + digits.clear() } + if (digits.size() > 16) printOneDigit() check() diff --git a/compiler/testData/psi/CallsInWhen.jet b/compiler/testData/psi/CallsInWhen.jet index ad63479bd65..2675ba89523 100644 --- a/compiler/testData/psi/CallsInWhen.jet +++ b/compiler/testData/psi/CallsInWhen.jet @@ -1,13 +1,13 @@ fun foo() { when (a) { - .foo => a - .foo() => a - .foo => a - .foo(a) => a - .foo(a, d) => a - .{bar} => a - .{!bar} => a - .{() => !bar} => a + a.foo => a + a.foo() => a + a.foo => a + a.foo(a) => a + a.foo(a, d) => a + a.{bar} => a + a.{!bar} => a + a.{() => !bar} => a else => a } } diff --git a/compiler/testData/psi/CallsInWhen.txt b/compiler/testData/psi/CallsInWhen.txt index dff80072a3d..c3992ac542b 100644 --- a/compiler/testData/psi/CallsInWhen.txt +++ b/compiler/testData/psi/CallsInWhen.txt @@ -22,10 +22,14 @@ JetFile: CallsInWhen.jet PsiElement(LBRACE)('{') PsiWhiteSpace('\n ') WHEN_ENTRY - WHEN_CONDITION_CALL - PsiElement(DOT)('.') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') + WHEN_CONDITION_IS_PATTERN + EXPRESSION_PATTERN + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(DOT)('.') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') PsiWhiteSpace(' ') PsiElement(DOUBLE_ARROW)('=>') PsiWhiteSpace(' ') @@ -33,14 +37,18 @@ JetFile: CallsInWhen.jet PsiElement(IDENTIFIER)('a') PsiWhiteSpace('\n ') WHEN_ENTRY - WHEN_CONDITION_CALL - PsiElement(DOT)('.') - CALL_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - VALUE_ARGUMENT_LIST - PsiElement(LPAR)('(') - PsiElement(RPAR)(')') + WHEN_CONDITION_IS_PATTERN + EXPRESSION_PATTERN + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(DOT)('.') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') PsiWhiteSpace(' ') PsiElement(DOUBLE_ARROW)('=>') PsiWhiteSpace(' ') @@ -48,19 +56,53 @@ JetFile: CallsInWhen.jet PsiElement(IDENTIFIER)('a') PsiWhiteSpace('\n ') WHEN_ENTRY - WHEN_CONDITION_CALL - PsiElement(DOT)('.') - CALL_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - TYPE_ARGUMENT_LIST - PsiElement(LT)('<') - TYPE_PROJECTION - TYPE_REFERENCE - USER_TYPE + WHEN_CONDITION_IS_PATTERN + EXPRESSION_PATTERN + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(DOT)('.') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + TYPE_ARGUMENT_LIST + PsiElement(LT)('<') + TYPE_PROJECTION + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + PsiWhiteSpace(' ') + PsiElement(DOUBLE_ARROW)('=>') + PsiWhiteSpace(' ') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiWhiteSpace('\n ') + WHEN_ENTRY + WHEN_CONDITION_IS_PATTERN + EXPRESSION_PATTERN + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(DOT)('.') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + TYPE_ARGUMENT_LIST + PsiElement(LT)('<') + TYPE_PROJECTION + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(GT)('>') + PsiElement(IDENTIFIER)('a') + PsiElement(RPAR)(')') PsiWhiteSpace(' ') PsiElement(DOUBLE_ARROW)('=>') PsiWhiteSpace(' ') @@ -68,56 +110,34 @@ JetFile: CallsInWhen.jet PsiElement(IDENTIFIER)('a') PsiWhiteSpace('\n ') WHEN_ENTRY - WHEN_CONDITION_CALL - PsiElement(DOT)('.') - CALL_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - TYPE_ARGUMENT_LIST - PsiElement(LT)('<') - TYPE_PROJECTION - TYPE_REFERENCE - USER_TYPE + WHEN_CONDITION_IS_PATTERN + EXPRESSION_PATTERN + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(DOT)('.') + CALL_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('foo') + TYPE_ARGUMENT_LIST + PsiElement(LT)('<') + TYPE_PROJECTION + TYPE_REFERENCE + USER_TYPE + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('T') + PsiElement(GT)('>') + VALUE_ARGUMENT_LIST + PsiElement(LPAR)('(') + VALUE_ARGUMENT REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(GT)('>') - VALUE_ARGUMENT_LIST - PsiElement(LPAR)('(') - VALUE_ARGUMENT - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('a') - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - PsiElement(DOUBLE_ARROW)('=>') - PsiWhiteSpace(' ') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('a') - PsiWhiteSpace('\n ') - WHEN_ENTRY - WHEN_CONDITION_CALL - PsiElement(DOT)('.') - CALL_EXPRESSION - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('foo') - TYPE_ARGUMENT_LIST - PsiElement(LT)('<') - TYPE_PROJECTION - TYPE_REFERENCE - USER_TYPE + PsiElement(IDENTIFIER)('a') + PsiElement(COMMA)(',') + PsiWhiteSpace(' ') + VALUE_ARGUMENT REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('T') - PsiElement(GT)('>') - VALUE_ARGUMENT_LIST - PsiElement(LPAR)('(') - VALUE_ARGUMENT - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('a') - PsiElement(COMMA)(',') - PsiWhiteSpace(' ') - VALUE_ARGUMENT - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('d') - PsiElement(RPAR)(')') + PsiElement(IDENTIFIER)('d') + PsiElement(RPAR)(')') PsiWhiteSpace(' ') PsiElement(DOUBLE_ARROW)('=>') PsiWhiteSpace(' ') @@ -125,15 +145,19 @@ JetFile: CallsInWhen.jet PsiElement(IDENTIFIER)('a') PsiWhiteSpace('\n ') WHEN_ENTRY - WHEN_CONDITION_CALL - PsiElement(DOT)('.') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - BLOCK - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('bar') - PsiElement(RBRACE)('}') + WHEN_CONDITION_IS_PATTERN + EXPRESSION_PATTERN + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(DOT)('.') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + BLOCK + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + PsiElement(RBRACE)('}') PsiWhiteSpace(' ') PsiElement(DOUBLE_ARROW)('=>') PsiWhiteSpace(' ') @@ -141,18 +165,22 @@ JetFile: CallsInWhen.jet PsiElement(IDENTIFIER)('a') PsiWhiteSpace('\n ') WHEN_ENTRY - WHEN_CONDITION_CALL - PsiElement(DOT)('.') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - BLOCK - PREFIX_EXPRESSION - OPERATION_REFERENCE - PsiElement(EXCL)('!') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('bar') - PsiElement(RBRACE)('}') + WHEN_CONDITION_IS_PATTERN + EXPRESSION_PATTERN + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(DOT)('.') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + BLOCK + PREFIX_EXPRESSION + OPERATION_REFERENCE + PsiElement(EXCL)('!') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + PsiElement(RBRACE)('}') PsiWhiteSpace(' ') PsiElement(DOUBLE_ARROW)('=>') PsiWhiteSpace(' ') @@ -160,24 +188,28 @@ JetFile: CallsInWhen.jet PsiElement(IDENTIFIER)('a') PsiWhiteSpace('\n ') WHEN_ENTRY - WHEN_CONDITION_CALL - PsiElement(DOT)('.') - FUNCTION_LITERAL_EXPRESSION - FUNCTION_LITERAL - PsiElement(LBRACE)('{') - VALUE_PARAMETER_LIST - PsiElement(LPAR)('(') - PsiElement(RPAR)(')') - PsiWhiteSpace(' ') - PsiElement(DOUBLE_ARROW)('=>') - PsiWhiteSpace(' ') - BLOCK - PREFIX_EXPRESSION - OPERATION_REFERENCE - PsiElement(EXCL)('!') - REFERENCE_EXPRESSION - PsiElement(IDENTIFIER)('bar') - PsiElement(RBRACE)('}') + WHEN_CONDITION_IS_PATTERN + EXPRESSION_PATTERN + DOT_QUALIFIED_EXPRESSION + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('a') + PsiElement(DOT)('.') + FUNCTION_LITERAL_EXPRESSION + FUNCTION_LITERAL + PsiElement(LBRACE)('{') + VALUE_PARAMETER_LIST + PsiElement(LPAR)('(') + PsiElement(RPAR)(')') + PsiWhiteSpace(' ') + PsiElement(DOUBLE_ARROW)('=>') + PsiWhiteSpace(' ') + BLOCK + PREFIX_EXPRESSION + OPERATION_REFERENCE + PsiElement(EXCL)('!') + REFERENCE_EXPRESSION + PsiElement(IDENTIFIER)('bar') + PsiElement(RBRACE)('}') PsiWhiteSpace(' ') PsiElement(DOUBLE_ARROW)('=>') PsiWhiteSpace(' ') diff --git a/compiler/testData/psi/When_ERR.txt b/compiler/testData/psi/When_ERR.txt index dba08d47c7f..64b931828e9 100644 --- a/compiler/testData/psi/When_ERR.txt +++ b/compiler/testData/psi/When_ERR.txt @@ -82,7 +82,7 @@ JetFile: When_ERR.jet WHEN_ENTRY WHEN_CONDITION_IS_PATTERN EXPRESSION_PATTERN - PsiErrorElement:Expecting an element, is-condition or in-condition + PsiErrorElement:Expecting an expression, is-condition or in-condition PsiElement(DOUBLE_ARROW)('=>') PsiWhiteSpace(' ') @@ -164,7 +164,7 @@ JetFile: When_ERR.jet WHEN_ENTRY WHEN_CONDITION_IS_PATTERN EXPRESSION_PATTERN - PsiErrorElement:Expecting an element, is-condition or in-condition + PsiErrorElement:Expecting an expression, is-condition or in-condition PsiElement(DOUBLE_ARROW)('=>') PsiErrorElement:Expecting an element diff --git a/compiler/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java b/compiler/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java index 667415f53f3..a8d904c1707 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/PatternMatchingTest.java @@ -99,18 +99,19 @@ public class PatternMatchingTest extends CodegenTestCase { assertEquals("something", foo.invoke(null, new Tuple2(null, "not", "tuple"))); } - public void testCall() throws Exception { - loadText("fun foo(s: String) = when(s) { .startsWith(\"J\") => \"JetBrains\"; else => \"something\" }"); - Method foo = generateFunction(); - try { - assertEquals("JetBrains", foo.invoke(null, "Java")); - assertEquals("something", foo.invoke(null, "C#")); - } - catch (Throwable t) { - System.out.println(generateToText()); - t.printStackTrace(); - } - } + // Commented for KT-621 +// public void testCall() throws Exception { +// loadText("fun foo(s: String) = when(s) { .startsWith(\"J\") => \"JetBrains\"; else => \"something\" }"); +// Method foo = generateFunction(); +// try { +// assertEquals("JetBrains", foo.invoke(null, "Java")); +// assertEquals("something", foo.invoke(null, "C#")); +// } +// catch (Throwable t) { +// System.out.println(generateToText()); +// t.printStackTrace(); +// } +// } public void testCallProperty() throws Exception { blackBoxFile("patternMatching/callProperty.jet"); diff --git a/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceSafeCallWithDotCall.java b/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceSafeCallWithDotCall.java index d38fad55bcd..c6a18316996 100644 --- a/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceSafeCallWithDotCall.java +++ b/idea/src/org/jetbrains/jet/plugin/quickfix/ReplaceSafeCallWithDotCall.java @@ -40,13 +40,6 @@ public class ReplaceSafeCallWithDotCall extends JetIntentionAction { CodeEditUtil.replaceChild(newElement.getNode(), newElement.getSelectorExpression().getNode(), safeQualifiedExpression.getSelectorExpression().getNode()); CodeEditUtil.replaceChild(newElement.getNode(), newElement.getReceiverExpression().getNode(), safeQualifiedExpression.getReceiverExpression().getNode()); - element.replace(newElement); - } - else if (element instanceof JetWhenConditionCall) { - JetWhenConditionCall newElement = (JetWhenConditionCall) element; - JetDotQualifiedExpression callExpression = (JetDotQualifiedExpression) JetPsiFactory.createExpression(project, "x.foo"); - CodeEditUtil.replaceChild(newElement.getNode(), newElement.getOperationTokenNode(), callExpression.getOperationTokenNode()); - element.replace(newElement); } } diff --git a/idea/testData/checker/When.jet b/idea/testData/checker/When.jet index a7bd2a87103..c9e799dd41d 100644 --- a/idea/testData/checker/When.jet +++ b/idea/testData/checker/When.jet @@ -13,15 +13,18 @@ fun foo() : Int { 1 + a => 1 in 1..a => 1 !in 1..a => 1 - .a => 1 - .equals(1).a => 1 - ?.equals(1) => 1 + // Commented for KT-621 .a => 1 + // Commented for KT-621 .equals(1).a => 1 + // Commented for KT-621 ?.equals(1) => 1 else => 1 } - return when (x?:null) { - .foo() => 1 - ?.equals(1).equals(2) => 1 - } + + // Commented for KT-621 + // return when (x?:null) { + // .foo() => 1 + // ?.equals(1).equals(2) => 1 + // } + return 0 } val _type_test : Int = foo() // this is needed to ensure the inferred return type of foo() diff --git a/idea/testData/quickfix/expressions/beforeUnnecessarySafeCall2.kt b/idea/testData/quickfix/expressions/beforeUnnecessarySafeCall2.kt deleted file mode 100644 index cee0f9535b3..00000000000 --- a/idea/testData/quickfix/expressions/beforeUnnecessarySafeCall2.kt +++ /dev/null @@ -1,7 +0,0 @@ -// "Replace with dot call" "true" -fun foo(a: Any) { - when (a) { - ?.equals(0) => true - else => false - } -} \ No newline at end of file