Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Equality does not swallow errors #9560

Merged
merged 4 commits into from
Mar 29, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
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;
Expand Down Expand Up @@ -82,8 +81,7 @@ public static EqualsNode getUncached() {
* @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) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a builtin method does not handle DataflowError itself, it should not annotate parameters with @AcceptsError. In other words, if @AcceptsError annotation is used, there should be a specialization that handles DataflowErrors.

var areEqual = node.execute(frame, self, other);
if (!areEqual) {
var selfType = types.execute(self);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -630,7 +630,7 @@ public boolean isSuspended() {
}

/**
* @return whether thsi argument accepts a dataflow error.
* @return whether this argument accepts a dataflow error.
*/
public boolean acceptsError() {
return acceptsError;
Expand Down
11 changes: 11 additions & 0 deletions test/Base_Tests/src/Data/Ordering_Spec.enso
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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
Expand Down
8 changes: 8 additions & 0 deletions test/Base_Tests/src/Semantic/Equals_Spec.enso
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from Standard.Base import all
import Standard.Base.Errors.Illegal_State.Illegal_State

from Standard.Test import all

Expand Down Expand Up @@ -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
Expand Down
Loading