Tests for qualified 'this', 'break' and 'continue'
This commit is contained in:
@@ -5,6 +5,7 @@ package org.jetbrains.jet.lang.annotations;
|
||||
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.JetHighlighter;
|
||||
@@ -16,6 +17,7 @@ import org.jetbrains.jet.lexer.JetTokens;
|
||||
|
||||
public class LabelsAnnotator implements Annotator {
|
||||
public void annotate(@NotNull PsiElement element, @NotNull final AnnotationHolder holder) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) return;
|
||||
element.accept(new JetVisitor() {
|
||||
@Override
|
||||
public void visitPrefixExpression(JetPrefixExpression expression) {
|
||||
|
||||
@@ -110,6 +110,11 @@ public class JetControlFlowProcessor {
|
||||
value(expression.getExpression(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitThisExpression(JetThisExpression expression) {
|
||||
builder.readNode(expression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitConstantExpression(JetConstantExpression expression) {
|
||||
builder.readNode(expression);
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package org.jetbrains.jet.lang.resolve;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.jet.lang.JetSemanticServices;
|
||||
import org.jetbrains.jet.lang.cfg.JetControlFlowProcessor;
|
||||
@@ -232,17 +233,20 @@ public class TopDownAnalyzer {
|
||||
|
||||
JetExpression bodyExpression = function.getBodyExpression();
|
||||
if (bodyExpression != null) {
|
||||
System.out.println("-------------");
|
||||
JetControlFlowInstructionsGenerator instructionsGenerator = new JetControlFlowInstructionsGenerator(function);
|
||||
new JetControlFlowProcessor(semanticServices, trace, instructionsGenerator).generate(function, bodyExpression);
|
||||
Pseudocode pseudocode = instructionsGenerator.getPseudocode();
|
||||
pseudocode.postProcess();
|
||||
pseudocode.dumpInstructions(System.out);
|
||||
System.out.println("-------------");
|
||||
try {
|
||||
pseudocode.dumpGraph(new PrintStream("/Users/abreslav/work/cfg.dot"));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
|
||||
if (!ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
System.out.println("-------------");
|
||||
pseudocode.dumpInstructions(System.out);
|
||||
System.out.println("-------------");
|
||||
try {
|
||||
pseudocode.dumpGraph(new PrintStream("/Users/abreslav/work/cfg.dot"));
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -264,6 +264,7 @@ public class JetTypeInferrer {
|
||||
};
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private JetType getBlockReturnedType(@NotNull JetScope outerScope, @NotNull List<JetElement> block, @NotNull LabeledJumpDomain jumpDomain) {
|
||||
if (block.isEmpty()) {
|
||||
return JetStandardClasses.getUnitType();
|
||||
@@ -416,7 +417,9 @@ public class JetTypeInferrer {
|
||||
writableScope.setThisType(receiverType);
|
||||
returnType = getBlockReturnedType(writableScope, body, LabeledJumpDomain.ERROR);
|
||||
}
|
||||
result = JetStandardClasses.getFunctionType(null, receiverTypeRef == null ? null : receiverType, parameterTypes, returnType);
|
||||
JetType effectiveReceiverType = receiverTypeRef == null ? null : receiverType;
|
||||
JetType safeReturnType = returnType == null ? ErrorUtils.createErrorType("<return type>") : returnType;
|
||||
result = JetStandardClasses.getFunctionType(null, effectiveReceiverType, parameterTypes, safeReturnType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -0,0 +1,28 @@
|
||||
class C {
|
||||
|
||||
fun f (a : Boolean, b : Boolean) {
|
||||
@b (while (true)
|
||||
@a {
|
||||
<error>break@f</error>
|
||||
break
|
||||
break@b
|
||||
<error>break@a</error>
|
||||
})
|
||||
|
||||
<error>continue</error>
|
||||
|
||||
@b (while (true)
|
||||
@a {
|
||||
<error>continue@f</error>
|
||||
continue
|
||||
continue@b
|
||||
<error>continue@a</error>
|
||||
})
|
||||
|
||||
<error>break</error>
|
||||
|
||||
<error>continue@f</error>
|
||||
<error>break@f</error>
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,4 +31,8 @@ public class JetPsiCheckerTest extends LightDaemonAnalyzerTestCase {
|
||||
public void testQualifiedThis() throws Exception {
|
||||
doTest("/checker/QualifiedThis.jet", true, true);
|
||||
}
|
||||
|
||||
public void testBreakContinue() throws Exception {
|
||||
doTest("/checker/BreakContinue.jet", true, true);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user