support property access in pattern matching expressions

This commit is contained in:
Dmitry Jemerov
2011-07-06 20:17:38 +02:00
parent 8d28105a9e
commit d42eedb0e0
3 changed files with 23 additions and 0 deletions
@@ -1871,6 +1871,16 @@ public class ExpressionCodegen extends JetVisitor {
invokeMethodWithArguments(callableMethod, (JetCallExpression) call, true);
conditionValue = StackValue.onStack(Type.BOOLEAN_TYPE);
}
else if (call instanceof JetSimpleNameExpression) {
final DeclarationDescriptor descriptor = bindingContext.resolveReferenceExpression((JetSimpleNameExpression) call);
if (descriptor instanceof PropertyDescriptor) {
v.load(subjectLocal, subjectType);
conditionValue = intermediateValueForProperty((PropertyDescriptor) descriptor, false, false);
}
else {
throw new UnsupportedOperationException("unknown simple name resolve result: " + descriptor);
}
}
else {
throw new UnsupportedOperationException("unsupported kind of call suffix");
}
@@ -0,0 +1,9 @@
class C(val p: Boolean) { }
fun box(): String {
val c = C(true)
return when(c) {
.p => "OK"
else => "fail"
}
}
@@ -77,6 +77,10 @@ public class PatternMatchingTest extends CodegenTestCase {
assertEquals("something", foo.invoke(null, "C#"));
}
public void testCallProperty() throws Exception {
blackBoxFile("patternMatching/callProperty.jet");
}
public void testNames() throws Exception {
loadText("fun foo(x: (Any, Any)) = when(x) { is (val a is String, *) => a; else => \"something\" }");
Method foo = generateFunction();