Skip to content

Commit

Permalink
from conversion propagates dataflow error (#9856)
Browse files Browse the repository at this point in the history
Just add a dataflow error sentinel specialization to `InvokeConversionNode`.
  • Loading branch information
Akirathan authored May 3, 2024
1 parent 25d1007 commit 2af217c
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ static boolean hasType(TypeOfNode typeOfNode, Object value) {
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,
Expand All @@ -123,8 +128,9 @@ Object doConvertFrom(
}
}

/** 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,
Expand All @@ -143,6 +149,18 @@ Object doDataflowError(
}
}

/** 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,
Expand Down
9 changes: 9 additions & 0 deletions test/Base_Tests/src/Semantic/Conversion_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -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" <|
Expand Down

0 comments on commit 2af217c

Please sign in to comment.