From 634b25ca3740dbb3778b32c57b5c7ed6c79788c2 Mon Sep 17 00:00:00 2001 From: Jaroslav Tulach Date: Thu, 14 Sep 2023 09:34:54 +0200 Subject: [PATCH] Support foreign number argument in double arithmetic nodes --- .../builtin/number/decimal/AddNode.java | 22 ++++++++---- .../builtin/number/decimal/DivideNode.java | 17 ++++++++- .../builtin/number/decimal/FloatNode.java | 35 ++++++++++++++++++- .../builtin/number/decimal/GreaterNode.java | 15 ++++++++ .../number/decimal/GreaterOrEqualNode.java | 15 ++++++++ .../builtin/number/decimal/LessNode.java | 15 ++++++++ .../number/decimal/LessOrEqualNode.java | 15 ++++++++ .../builtin/number/decimal/ModNode.java | 17 ++++++++- .../builtin/number/decimal/MultiplyNode.java | 22 ++++++++---- .../builtin/number/decimal/PowNode.java | 17 ++++++++- .../builtin/number/decimal/SubtractNode.java | 17 ++++++++- .../interpreter/test/BinaryOpFloatTest.java | 2 +- test/Tests/src/Semantic/Conversion_Spec.enso | 21 +++++++++++ 13 files changed, 212 insertions(+), 18 deletions(-) diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/AddNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/AddNode.java index 056cb561defb..aa25f343a441 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/AddNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/AddNode.java @@ -1,12 +1,14 @@ package org.enso.interpreter.node.expression.builtin.number.decimal; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.interop.InteropLibrary; +import com.oracle.truffle.api.interop.TruffleObject; +import com.oracle.truffle.api.library.CachedLibrary; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps; -import org.enso.interpreter.runtime.EnsoContext; -import org.enso.interpreter.runtime.builtin.Builtins; -import org.enso.interpreter.runtime.error.PanicException; +import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode; import org.enso.interpreter.runtime.number.EnsoBigInteger; @BuiltinMethod(type = "Decimal", name = "+", description = "Addition of numbers.") @@ -32,10 +34,18 @@ static AddNode build() { return self + BigIntegerOps.toDouble(that.getValue()); } + @Specialization(guards = "isForeignNumber(iop, that)") + double doInterop( + double self, + TruffleObject that, + @CachedLibrary(limit = INTEROP_LIMIT) InteropLibrary iop, + @Cached ToEnsoNumberNode toEnsoNumberNode, + @Cached AddNode delegate) { + return delegate.execute(self, handleInterop(false, self, that, iop, toEnsoNumberNode)); + } + @Fallback double doOther(double self, Object that) { - Builtins builtins = EnsoContext.get(this).getBuiltins(); - var number = builtins.number().getNumber(); - throw new PanicException(builtins.error().makeTypeError(number, that, "that"), this); + throw panicOtherwise(self, that); } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/DivideNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/DivideNode.java index 83fea148e361..524e8bae95d0 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/DivideNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/DivideNode.java @@ -1,9 +1,14 @@ package org.enso.interpreter.node.expression.builtin.number.decimal; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.interop.InteropLibrary; +import com.oracle.truffle.api.interop.TruffleObject; +import com.oracle.truffle.api.library.CachedLibrary; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps; +import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode; import org.enso.interpreter.runtime.number.EnsoBigInteger; @BuiltinMethod(type = "Decimal", name = "/", description = "Division of numbers.") @@ -29,8 +34,18 @@ static DivideNode build() { return self / BigIntegerOps.toDouble(that.getValue()); } + @Specialization(guards = "isForeignNumber(iop, that)") + double doInterop( + double self, + TruffleObject that, + @CachedLibrary(limit = INTEROP_LIMIT) InteropLibrary iop, + @Cached ToEnsoNumberNode toEnsoNumberNode, + @Cached DivideNode delegate) { + return delegate.execute(self, handleInterop(false, self, that, iop, toEnsoNumberNode)); + } + @Fallback double doOther(double self, Object that) { - return handleOther(self, that); + throw panicOtherwise(self, that); } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/FloatNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/FloatNode.java index 2f9d481ac97c..a6e9a10feb9a 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/FloatNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/FloatNode.java @@ -1,12 +1,45 @@ package org.enso.interpreter.node.expression.builtin.number.decimal; +import com.oracle.truffle.api.interop.InteropLibrary; +import com.oracle.truffle.api.interop.TruffleObject; +import com.oracle.truffle.api.interop.UnsupportedMessageException; import com.oracle.truffle.api.nodes.Node; +import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode; import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.error.DataflowError; import org.enso.interpreter.runtime.error.PanicException; +import org.enso.interpreter.runtime.number.EnsoBigInteger; abstract class FloatNode extends Node { - final double handleOther(double self, Object that) { + static final String INTEROP_LIMIT = "3"; + + final boolean isForeignNumber(InteropLibrary iop, TruffleObject obj) { + if (obj instanceof EnsoBigInteger) { + return false; + } + return iop.isNumber(obj); + } + + final Object handleInterop( + boolean incomparableError, + double self, + TruffleObject that, + InteropLibrary iop, + ToEnsoNumberNode toEnsoNumberNode) { + try { + if (iop.fitsInLong(that)) { + return iop.asLong(that); + } else if (iop.fitsInDouble(that)) { + return iop.asDouble(that); + } else if (iop.fitsInBigInteger(that)) { + return toEnsoNumberNode.execute(iop.asBigInteger(that)); + } + } catch (UnsupportedMessageException ex) { + } + return incomparableError ? incomparableError(self, that) : panicOtherwise(self, that); + } + + final PanicException panicOtherwise(double self, Object that) { var builtins = EnsoContext.get(this).getBuiltins(); var number = builtins.number().getNumber(); throw new PanicException(builtins.error().makeTypeError(number, that, "that"), this); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/GreaterNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/GreaterNode.java index 61efbbc234d9..d18489ec5a21 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/GreaterNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/GreaterNode.java @@ -1,9 +1,14 @@ package org.enso.interpreter.node.expression.builtin.number.decimal; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.interop.InteropLibrary; +import com.oracle.truffle.api.interop.TruffleObject; +import com.oracle.truffle.api.library.CachedLibrary; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps; +import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode; import org.enso.interpreter.runtime.number.EnsoBigInteger; @BuiltinMethod(type = "Decimal", name = ">", description = "Comparison of numbers.") @@ -42,6 +47,16 @@ Object doBigInteger(double self, EnsoBigInteger that) { } } + @Specialization(guards = "isForeignNumber(iop, that)") + Object doInterop( + double self, + TruffleObject that, + @CachedLibrary(limit = INTEROP_LIMIT) InteropLibrary iop, + @Cached ToEnsoNumberNode toEnsoNumberNode, + @Cached GreaterNode delegate) { + return delegate.execute(self, handleInterop(true, self, that, iop, toEnsoNumberNode)); + } + @Fallback Object doOther(double self, Object that) { return incomparableError(self, that); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/GreaterOrEqualNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/GreaterOrEqualNode.java index 0c0edd3b658e..b733ef468581 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/GreaterOrEqualNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/GreaterOrEqualNode.java @@ -1,9 +1,14 @@ package org.enso.interpreter.node.expression.builtin.number.decimal; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.interop.InteropLibrary; +import com.oracle.truffle.api.interop.TruffleObject; +import com.oracle.truffle.api.library.CachedLibrary; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps; +import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode; import org.enso.interpreter.runtime.number.EnsoBigInteger; @BuiltinMethod(type = "Decimal", name = ">=", description = "Comparison of numbers.") @@ -42,6 +47,16 @@ Object doBigInteger(double self, EnsoBigInteger that) { } } + @Specialization(guards = "isForeignNumber(iop, that)") + Object doInterop( + double self, + TruffleObject that, + @CachedLibrary(limit = INTEROP_LIMIT) InteropLibrary iop, + @Cached ToEnsoNumberNode toEnsoNumberNode, + @Cached GreaterOrEqualNode delegate) { + return delegate.execute(self, handleInterop(true, self, that, iop, toEnsoNumberNode)); + } + @Fallback Object doOther(double self, Object that) { return incomparableError(self, that); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/LessNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/LessNode.java index 2f7cd40f5552..18f780d5f023 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/LessNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/LessNode.java @@ -1,9 +1,14 @@ package org.enso.interpreter.node.expression.builtin.number.decimal; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.interop.InteropLibrary; +import com.oracle.truffle.api.interop.TruffleObject; +import com.oracle.truffle.api.library.CachedLibrary; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps; +import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode; import org.enso.interpreter.runtime.number.EnsoBigInteger; @BuiltinMethod(type = "Decimal", name = "<", description = "Comparison of numbers.") @@ -42,6 +47,16 @@ Object doBigInteger(double self, EnsoBigInteger that) { } } + @Specialization(guards = "isForeignNumber(iop, that)") + Object doInterop( + double self, + TruffleObject that, + @CachedLibrary(limit = INTEROP_LIMIT) InteropLibrary iop, + @Cached ToEnsoNumberNode toEnsoNumberNode, + @Cached LessNode delegate) { + return delegate.execute(self, handleInterop(true, self, that, iop, toEnsoNumberNode)); + } + @Fallback Object doOther(double self, Object that) { return incomparableError(self, that); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/LessOrEqualNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/LessOrEqualNode.java index 0f892dc16f3f..0675c71da188 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/LessOrEqualNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/LessOrEqualNode.java @@ -1,9 +1,14 @@ package org.enso.interpreter.node.expression.builtin.number.decimal; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.interop.InteropLibrary; +import com.oracle.truffle.api.interop.TruffleObject; +import com.oracle.truffle.api.library.CachedLibrary; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps; +import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode; import org.enso.interpreter.runtime.number.EnsoBigInteger; @BuiltinMethod(type = "Decimal", name = "<=", description = "Comparison of numbers.") @@ -42,6 +47,16 @@ Object doBigInteger(double self, EnsoBigInteger that) { } } + @Specialization(guards = "isForeignNumber(iop, that)") + Object doInterop( + double self, + TruffleObject that, + @CachedLibrary(limit = INTEROP_LIMIT) InteropLibrary iop, + @Cached ToEnsoNumberNode toEnsoNumberNode, + @Cached LessOrEqualNode delegate) { + return delegate.execute(self, handleInterop(true, self, that, iop, toEnsoNumberNode)); + } + @Fallback Object doOther(double self, Object that) { return incomparableError(self, that); diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/ModNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/ModNode.java index b8848d5dcc7e..2e1a16fa0ac5 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/ModNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/ModNode.java @@ -1,9 +1,14 @@ package org.enso.interpreter.node.expression.builtin.number.decimal; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.interop.InteropLibrary; +import com.oracle.truffle.api.interop.TruffleObject; +import com.oracle.truffle.api.library.CachedLibrary; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps; +import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode; import org.enso.interpreter.runtime.number.EnsoBigInteger; @BuiltinMethod(type = "Decimal", name = "%", description = "Modulo division of numbers.") @@ -29,8 +34,18 @@ static ModNode build() { return self % BigIntegerOps.toDouble(that.getValue()); } + @Specialization(guards = "isForeignNumber(iop, that)") + double doInterop( + double self, + TruffleObject that, + @CachedLibrary(limit = INTEROP_LIMIT) InteropLibrary iop, + @Cached ToEnsoNumberNode toEnsoNumberNode, + @Cached ModNode delegate) { + return delegate.execute(self, handleInterop(false, self, that, iop, toEnsoNumberNode)); + } + @Fallback double doOther(double self, Object that) { - return handleOther(self, that); + throw panicOtherwise(self, that); } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/MultiplyNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/MultiplyNode.java index 31d9115577e9..3344d9088777 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/MultiplyNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/MultiplyNode.java @@ -1,12 +1,14 @@ package org.enso.interpreter.node.expression.builtin.number.decimal; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.interop.InteropLibrary; +import com.oracle.truffle.api.interop.TruffleObject; +import com.oracle.truffle.api.library.CachedLibrary; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps; -import org.enso.interpreter.runtime.EnsoContext; -import org.enso.interpreter.runtime.builtin.Builtins; -import org.enso.interpreter.runtime.error.PanicException; +import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode; import org.enso.interpreter.runtime.number.EnsoBigInteger; @BuiltinMethod(type = "Decimal", name = "*", description = "Multiplication of numbers.") @@ -32,10 +34,18 @@ static MultiplyNode build() { return self * BigIntegerOps.toDouble(that.getValue()); } + @Specialization(guards = "isForeignNumber(iop, that)") + double doInterop( + double self, + TruffleObject that, + @CachedLibrary(limit = INTEROP_LIMIT) InteropLibrary iop, + @Cached ToEnsoNumberNode toEnsoNumberNode, + @Cached MultiplyNode delegate) { + return delegate.execute(self, handleInterop(false, self, that, iop, toEnsoNumberNode)); + } + @Fallback double doOther(double self, Object that) { - Builtins builtins = EnsoContext.get(this).getBuiltins(); - var number = builtins.number().getNumber(); - throw new PanicException(builtins.error().makeTypeError(number, that, "that"), this); + throw panicOtherwise(self, that); } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/PowNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/PowNode.java index 7886f796b38c..4d60748e7120 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/PowNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/PowNode.java @@ -1,9 +1,14 @@ package org.enso.interpreter.node.expression.builtin.number.decimal; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.interop.InteropLibrary; +import com.oracle.truffle.api.interop.TruffleObject; +import com.oracle.truffle.api.library.CachedLibrary; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps; +import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode; import org.enso.interpreter.runtime.number.EnsoBigInteger; @BuiltinMethod(type = "Decimal", name = "^", description = "Exponentiation of numbers.") @@ -29,8 +34,18 @@ static PowNode build() { return Math.pow(self, BigIntegerOps.toDouble(that.getValue())); } + @Specialization(guards = "isForeignNumber(iop, that)") + double doInterop( + double self, + TruffleObject that, + @CachedLibrary(limit = INTEROP_LIMIT) InteropLibrary iop, + @Cached ToEnsoNumberNode toEnsoNumberNode, + @Cached PowNode delegate) { + return delegate.execute(self, handleInterop(false, self, that, iop, toEnsoNumberNode)); + } + @Fallback double doOther(double self, Object that) { - return handleOther(self, that); + throw panicOtherwise(self, that); } } diff --git a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/SubtractNode.java b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/SubtractNode.java index c312664036eb..63eb517b7f54 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/SubtractNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/node/expression/builtin/number/decimal/SubtractNode.java @@ -1,9 +1,14 @@ package org.enso.interpreter.node.expression.builtin.number.decimal; +import com.oracle.truffle.api.dsl.Cached; import com.oracle.truffle.api.dsl.Fallback; import com.oracle.truffle.api.dsl.Specialization; +import com.oracle.truffle.api.interop.InteropLibrary; +import com.oracle.truffle.api.interop.TruffleObject; +import com.oracle.truffle.api.library.CachedLibrary; import org.enso.interpreter.dsl.BuiltinMethod; import org.enso.interpreter.node.expression.builtin.number.utils.BigIntegerOps; +import org.enso.interpreter.node.expression.builtin.number.utils.ToEnsoNumberNode; import org.enso.interpreter.runtime.number.EnsoBigInteger; @BuiltinMethod(type = "Decimal", name = "-", description = "Subtraction of numbers.") @@ -29,8 +34,18 @@ static SubtractNode build() { return self - BigIntegerOps.toDouble(that.getValue()); } + @Specialization(guards = "isForeignNumber(iop, that)") + double doInterop( + double self, + TruffleObject that, + @CachedLibrary(limit = INTEROP_LIMIT) InteropLibrary iop, + @Cached ToEnsoNumberNode toEnsoNumberNode, + @Cached SubtractNode delegate) { + return delegate.execute(self, handleInterop(false, self, that, iop, toEnsoNumberNode)); + } + @Fallback double doOther(double self, Object that) { - return handleOther(self, that); + throw panicOtherwise(self, that); } } diff --git a/engine/runtime/src/test/java/org/enso/interpreter/test/BinaryOpFloatTest.java b/engine/runtime/src/test/java/org/enso/interpreter/test/BinaryOpFloatTest.java index 5782867db2e7..d0e19fa40ff3 100644 --- a/engine/runtime/src/test/java/org/enso/interpreter/test/BinaryOpFloatTest.java +++ b/engine/runtime/src/test/java/org/enso/interpreter/test/BinaryOpFloatTest.java @@ -85,7 +85,7 @@ public void verifyOperationOnForeignObject() { var r1 = execute(fn, n1, n2); - var wrap2 = n2; //ctx.asValue(new WrappedPrimitive(n2)); + var wrap2 = ctx.asValue(new WrappedPrimitive(n2)); var r2 = execute(fn, n1, wrap2); assertSameResult(r1, r2); diff --git a/test/Tests/src/Semantic/Conversion_Spec.enso b/test/Tests/src/Semantic/Conversion_Spec.enso index 35f36848651e..40a52c6b40e7 100644 --- a/test/Tests/src/Semantic/Conversion_Spec.enso +++ b/test/Tests/src/Semantic/Conversion_Spec.enso @@ -233,6 +233,27 @@ spec = do_number 42 + Test.specify "Requesting Decimal & Fool" <| + do_number (x : Decimal & Fool) = + x.foo . should_equal "foo called" + x.fool . should_equal 42.3 + x==x . should_be_true + (x:Decimal)==42.3 . should_be_true + (x:Fool)==42.3 . should_be_false + x==42.3 . should_be_true + 42.3==(x.to Decimal) . should_be_true + 42.3==(x.to Fool) . should_be_false + 42.3==x . should_be_true + 100+(x:Decimal) . should_equal 142.3 + (x:Decimal)+100 . should_equal 142.3 + x+100 . should_equal 142.3 + 100+x . should_equal 142.3 + x.to_text . should_equal "{FOOL 42.3}" + (x:Fool).to_text . should_equal "{FOOL 42.3}" + (x:Decimal).to_text . should_equal "42.3" + + do_number 42.3 + Test.specify "Requesting Boolean & Fool" <| do_boolean (x : Boolean & Fool) = x.fool . should_equal True