support property access in pattern matching expressions
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user