from conversion propagates dataflow error (#9856)

Just add a dataflow error sentinel specialization to `InvokeConversionNode`.
This commit is contained in:
Pavel Marek 2024-05-03 16:48:55 +02:00 committed by GitHub
parent 25d1007a9e
commit 2af217c3e6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 29 additions and 2 deletions

View File

@ -103,7 +103,12 @@ public abstract class InvokeConversionNode extends BaseNode {
return typeOfNode.execute(value) instanceof Type;
}
@Specialization(guards = {"hasType(dispatch, that)"})
static boolean isDataflowError(Object value) {
return value instanceof DataflowError;
}
@Specialization(
guards = {"hasType(dispatch, that)", "!isDataflowError(self)", "!isDataflowError(that)"})
Object doConvertFrom(
VirtualFrame frame,
State state,
@ -123,8 +128,9 @@ public abstract class InvokeConversionNode extends BaseNode {
}
}
/** If {@code that} is a dataflow error, we try to find a conversion for it. */
@Specialization
Object doDataflowError(
Object doConvertDataflowError(
VirtualFrame frame,
State state,
UnresolvedConversion conversion,
@ -143,6 +149,18 @@ public abstract class InvokeConversionNode extends BaseNode {
}
}
/** If {@code self} is a dataflow error, we just propagate it. */
@Specialization
Object doDataflowErrorSentinel(
VirtualFrame frame,
State state,
UnresolvedConversion conversion,
DataflowError self,
Object that,
Object[] arguments) {
return self;
}
@Specialization
Object doPanicSentinel(
VirtualFrame frame,

View File

@ -135,6 +135,15 @@ add_specs suite_builder =
group_builder.specify "should call extension conversions" <|
Text.from Methods.get_bar . should_equal "bar"
group_builder.specify "should propagate dataflow errors on builtin type" <|
Float.from 42 . is_error . should_be_false
Float.from (Error.throw "ERR") . is_error . should_be_true
(Error.throw "ERR") . to Float . is_error . should_be_true
group_builder.specify "should propagate dataflow errors on custom type" <|
Bar.from (Error.throw "ERR") . is_error . should_be_true
(Error.throw "ERR") . to Bar . is_error . should_be_true
group_builder.specify "should fail graciously when there is no conversion" <|
Panic.recover Any (Foo.from (Quux.Value 10)) . catch Any .to_display_text . should_equal "Could not find a conversion from `Quux.Value` to `Foo`."
group_builder.specify "should fail graciously when the conversion target is invalid" <|