mirror of
https://github.com/enso-org/enso.git
synced 2024-09-11 13:15:52 +03:00
Equality does not swallow errors (#9560)
`42 == (Error.throw "foo")` now correctly returns an `Error` rather than False # Important Notes The error was in the wrong usage of the `org.enso.interpreter.dsl.AcceptsError` DSL annotation.
This commit is contained in:
parent
c725703f50
commit
0b94493258
@ -27,13 +27,10 @@ type Enso_Path
|
||||
if raw_segments.is_empty then Error.throw (Illegal_Argument.Error "Invalid path - it should contain at least one segment.") else
|
||||
organization_name = raw_segments.first
|
||||
segments = raw_segments.drop 1 . filter s-> s.is_empty.not
|
||||
current_user_name = Enso_User.current.name
|
||||
# The `if_not_error` is a workaround for https://github.com/enso-org/enso/issues/9283 and it can be removed after that is fixed.
|
||||
current_user_name.if_not_error <|
|
||||
if organization_name != current_user_name then Unimplemented.throw "Currently only resolving paths for the current user is supported." else
|
||||
if segments.is_empty then Enso_Path.Value organization_name [] Nothing else
|
||||
asset_name = segments.last
|
||||
Enso_Path.Value organization_name (segments.drop (Index_Sub_Range.Last 1)) asset_name
|
||||
if organization_name != Enso_User.current.name then Unimplemented.throw "Currently only resolving paths for the current user is supported." else
|
||||
if segments.is_empty then Enso_Path.Value organization_name [] Nothing else
|
||||
asset_name = segments.last
|
||||
Enso_Path.Value organization_name (segments.drop (Index_Sub_Range.Last 1)) asset_name
|
||||
|
||||
## PRIVATE
|
||||
resolve_parent self =
|
||||
|
@ -9,7 +9,6 @@ import com.oracle.truffle.api.dsl.Specialization;
|
||||
import com.oracle.truffle.api.frame.VirtualFrame;
|
||||
import com.oracle.truffle.api.interop.ArityException;
|
||||
import com.oracle.truffle.api.nodes.Node;
|
||||
import org.enso.interpreter.dsl.AcceptsError;
|
||||
import org.enso.interpreter.dsl.BuiltinMethod;
|
||||
import org.enso.interpreter.node.EnsoRootNode;
|
||||
import org.enso.interpreter.node.callable.InteropConversionCallNode;
|
||||
@ -82,8 +81,7 @@ public final class EqualsNode extends Node {
|
||||
* @param other the other object
|
||||
* @return {@code true} if {@code self} and {@code that} seem equal
|
||||
*/
|
||||
public boolean execute(
|
||||
VirtualFrame frame, @AcceptsError Object self, @AcceptsError Object other) {
|
||||
public boolean execute(VirtualFrame frame, Object self, Object other) {
|
||||
var areEqual = node.execute(frame, self, other);
|
||||
if (!areEqual) {
|
||||
var selfType = types.execute(self);
|
||||
|
@ -630,7 +630,7 @@ public class MethodDefinition {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether thsi argument accepts a dataflow error.
|
||||
* @return whether this argument accepts a dataflow error.
|
||||
*/
|
||||
public boolean acceptsError() {
|
||||
return acceptsError;
|
||||
|
@ -1,6 +1,7 @@
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Errors.Common.Incomparable_Values
|
||||
import Standard.Base.Errors.Common.Type_Error
|
||||
import Standard.Base.Errors.Illegal_State.Illegal_State
|
||||
|
||||
from Standard.Test import all
|
||||
|
||||
@ -91,6 +92,16 @@ add_specs suite_builder =
|
||||
group_builder.specify "should throw Incomparable_Values when comparing Number with Nothing" <|
|
||||
Ordering.compare 1 Nothing . should_fail_with Incomparable_Values
|
||||
|
||||
group_builder.specify "should propagate errors" <|
|
||||
((Error.throw (Illegal_State.Error "foo" )) > 42) . should_fail_with Illegal_State
|
||||
((Error.throw (Illegal_State.Error "foo" )) >= 42) . should_fail_with Illegal_State
|
||||
((Error.throw (Illegal_State.Error "foo" )) < 42) . should_fail_with Illegal_State
|
||||
((Error.throw (Illegal_State.Error "foo" )) <= 42) . should_fail_with Illegal_State
|
||||
(42 > (Error.throw (Illegal_State.Error "foo" ))) . should_fail_with Illegal_State
|
||||
(42 >= (Error.throw (Illegal_State.Error "foo" ))) . should_fail_with Illegal_State
|
||||
(42 < (Error.throw (Illegal_State.Error "foo" ))) . should_fail_with Illegal_State
|
||||
(42 <= (Error.throw (Illegal_State.Error "foo" ))) . should_fail_with Illegal_State
|
||||
|
||||
suite_builder.group "Ordering" group_builder->
|
||||
group_builder.specify "should allow conversion to sign representation" <|
|
||||
Ordering.Less.to_sign . should_equal -1
|
||||
|
@ -1,4 +1,5 @@
|
||||
from Standard.Base import all
|
||||
import Standard.Base.Errors.Illegal_State.Illegal_State
|
||||
|
||||
from Standard.Test import all
|
||||
|
||||
@ -229,6 +230,13 @@ add_specs suite_builder =
|
||||
f2 = CustomEqType.C2 10
|
||||
f1==f2 . should_be_false
|
||||
|
||||
group_builder.specify "should propagate errors" <|
|
||||
((Error.throw (Illegal_State.Error "foo" )) == 42) . should_fail_with Illegal_State
|
||||
((Error.throw (Illegal_State.Error "foo" )) != 42) . should_fail_with Illegal_State
|
||||
(42 == (Error.throw (Illegal_State.Error "foo" ))) . should_fail_with Illegal_State
|
||||
(42 != (Error.throw (Illegal_State.Error "foo" ))) . should_fail_with Illegal_State
|
||||
|
||||
|
||||
suite_builder.group "Polyglot Operator ==" group_builder->
|
||||
group_builder.specify "should not try to compare members" <|
|
||||
x = IntHolder.new 5
|
||||
|
Loading…
Reference in New Issue
Block a user