Basic type patterns supported in when() expressions
This commit is contained in:
@@ -649,12 +649,25 @@ public class JetControlFlowProcessor {
|
||||
|
||||
@Override
|
||||
public void visitWhenConditionIsPattern(JetWhenConditionIsPattern condition) {
|
||||
super.visitWhenConditionIsPattern(condition); // TODO
|
||||
JetPattern pattern = condition.getPattern();
|
||||
if (pattern != null) {
|
||||
pattern.accept(new JetVisitor() {
|
||||
@Override
|
||||
public void visitTypePattern(JetTypePattern typePattern) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitJetElement(JetElement elem) {
|
||||
throw new UnsupportedOperationException(elem.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitJetElement(JetElement elem) {
|
||||
throw new UnsupportedOperationException();
|
||||
throw new UnsupportedOperationException(elem.toString());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -16,4 +16,9 @@ public class JetTypePattern extends JetPattern {
|
||||
public JetTypeReference getTypeReference() {
|
||||
return findChildByClass(JetTypeReference.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accept(@NotNull JetVisitor visitor) {
|
||||
visitor.visitTypePattern(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,4 +365,12 @@ public class JetVisitor extends PsiElementVisitor {
|
||||
public void visitWhenConditionInRange(JetWhenConditionInRange condition) {
|
||||
visitJetElement(condition);
|
||||
}
|
||||
|
||||
public void visitTypePattern(JetTypePattern typePattern) {
|
||||
visitPattern(typePattern);
|
||||
}
|
||||
|
||||
public void visitPattern(JetPattern pattern) {
|
||||
visitJetElement(pattern);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1019,7 +1019,26 @@ public class JetTypeInferrer {
|
||||
|
||||
@Override
|
||||
public void visitWhenConditionIsPattern(JetWhenConditionIsPattern condition) {
|
||||
super.visitWhenConditionIsPattern(condition); // TODO
|
||||
JetPattern pattern = condition.getPattern();
|
||||
if (pattern != null) {
|
||||
pattern.accept(new JetVisitor() {
|
||||
@Override
|
||||
public void visitTypePattern(JetTypePattern typePattern) {
|
||||
JetTypeReference typeReference = typePattern.getTypeReference();
|
||||
if (typeReference != null) {
|
||||
JetType type = typeResolver.resolveType(scope, typeReference);
|
||||
if (TypeUtils.intersect(semanticServices.getTypeChecker(), Sets.newHashSet(type, finalSubjectType)) == null) {
|
||||
trace.getErrorHandler().genericError(typePattern.getNode(), "Incompatible types"); // TODO : message
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitJetElement(JetElement elem) {
|
||||
trace.getErrorHandler().genericError(elem.getNode(), "Unsupported [JetTypeInferrer]");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -2,6 +2,9 @@ fun foo() {
|
||||
val s = ""
|
||||
val x = 1
|
||||
when (x) {
|
||||
is <error>String</error> => 1
|
||||
!is Int => 1
|
||||
is Any? => 1
|
||||
<error>s</error> => 1
|
||||
1 => 1
|
||||
1 + <error>a</error> => 1
|
||||
|
||||
Reference in New Issue
Block a user