Labels on function literal arguments are processed properly
This commit is contained in:
@@ -19,7 +19,6 @@ package org.jetbrains.jet.lang.psi;
|
||||
import com.intellij.lang.ASTNode;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.psi.PsiReferenceService;
|
||||
import com.intellij.psi.impl.source.resolve.reference.ReferenceProvidersRegistry;
|
||||
import com.intellij.util.SmartList;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -98,7 +97,7 @@ public class JetCallExpression extends JetReferenceExpression implements JetCall
|
||||
if (JetTokens.LABELS.contains(prefixExpression.getOperationReference().getReferencedNameElementType())) {
|
||||
JetExpression labeledExpression = prefixExpression.getBaseExpression();
|
||||
if (labeledExpression instanceof JetFunctionLiteralExpression) {
|
||||
result.add(labeledExpression);
|
||||
result.add(prefixExpression);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-10
@@ -215,15 +215,6 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
setStatus(ERROR);
|
||||
}
|
||||
else {
|
||||
JetFunctionLiteralExpression functionLiteral;
|
||||
if (possiblyLabeledFunctionLiteral instanceof JetLabelQualifiedExpression) {
|
||||
JetLabelQualifiedExpression labeledFunctionLiteral = (JetLabelQualifiedExpression) possiblyLabeledFunctionLiteral;
|
||||
functionLiteral = (JetFunctionLiteralExpression) labeledFunctionLiteral.getLabeledExpression();
|
||||
}
|
||||
else {
|
||||
functionLiteral = (JetFunctionLiteralExpression) possiblyLabeledFunctionLiteral;
|
||||
}
|
||||
|
||||
ValueParameterDescriptor valueParameterDescriptor = valueParameters.get(valueParameters.size() - 1);
|
||||
if (valueParameterDescriptor.getVarargElementType() != null) {
|
||||
report(VARARG_OUTSIDE_PARENTHESES.on(possiblyLabeledFunctionLiteral));
|
||||
@@ -235,7 +226,7 @@ import static org.jetbrains.jet.lang.resolve.calls.ValueArgumentsToParametersMap
|
||||
setStatus(WEAK_ERROR);
|
||||
}
|
||||
else {
|
||||
putVararg(valueParameterDescriptor, CallMaker.makeValueArgument(functionLiteral));
|
||||
putVararg(valueParameterDescriptor, CallMaker.makeValueArgument(possiblyLabeledFunctionLiteral));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
@@ -0,0 +1,5 @@
|
||||
fun test2() {
|
||||
run @f{return@f 1}
|
||||
}
|
||||
|
||||
fun run<T>(f: () -> T): T { return f() }
|
||||
+10
@@ -0,0 +1,10 @@
|
||||
fun test() {
|
||||
run(@f{return@f 1})
|
||||
}
|
||||
|
||||
|
||||
fun test1() {
|
||||
run(@{return@ 1})
|
||||
}
|
||||
|
||||
fun run<T>(f: () -> T): T { return f() }
|
||||
@@ -2436,6 +2436,17 @@ public class JetDiagnosticsTestGenerated extends AbstractDiagnosticsTestWithEage
|
||||
public void testForbiddenNonLocalReturnNoType() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/functionLiterals/return/ForbiddenNonLocalReturnNoType.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("LocalReturnExplicitLabelNoParens.kt")
|
||||
public void testLocalReturnExplicitLabelNoParens() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelNoParens.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("LocalReturnExplicitLabelParens.kt")
|
||||
public void testLocalReturnExplicitLabelParens() throws Exception {
|
||||
doTest("compiler/testData/diagnostics/tests/functionLiterals/return/LocalReturnExplicitLabelParens.kt");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static Test innerSuite() {
|
||||
|
||||
@@ -148,8 +148,8 @@ public class JetTypeCheckerTest extends JetLiteFixture {
|
||||
public void testIf() throws Exception {
|
||||
assertType("if (true) 1", "Unit");
|
||||
assertType("if (true) 1 else 1", "Int");
|
||||
assertType("if (true) 1 else return", "Int");
|
||||
assertType("if (true) return else 1", "Int");
|
||||
assertType("if (true) 1 else throw Exception()", "Int");
|
||||
assertType("if (true) throw Exception() else 1", "Int");
|
||||
assertType("if (true) throw Exception() else throw Exception()", "Nothing");
|
||||
|
||||
assertType("if (true) 1 else null", "Int?");
|
||||
|
||||
Reference in New Issue
Block a user