diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/library/dispatch/TypeOfNode.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/library/dispatch/TypeOfNode.java index e7641ff02435..5d5baa4c2af0 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/library/dispatch/TypeOfNode.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/library/dispatch/TypeOfNode.java @@ -15,6 +15,7 @@ import org.enso.interpreter.runtime.EnsoContext; import org.enso.interpreter.runtime.builtin.Builtins; import org.enso.interpreter.runtime.callable.UnresolvedSymbol; +import org.enso.interpreter.runtime.data.EnsoMultiValue; import org.enso.interpreter.runtime.data.EnsoObject; import org.enso.interpreter.runtime.data.Type; import org.enso.interpreter.runtime.error.DataflowError; @@ -74,6 +75,16 @@ Object doWarning(WithWarnings value, @Cached TypeOfNode withoutWarning) { return withoutWarning.execute(value.getValue()); } + static boolean isWithType(Object value, TypesLibrary types, InteropLibrary iop) { + if (value instanceof EnsoMultiValue) { + return true; + } + if (iop.isNumber(value)) { + return false; + } + return types.hasType(value); + } + static boolean isWithoutType(Object value, TypesLibrary types) { if (value instanceof EnsoObject) { return false; @@ -94,7 +105,7 @@ Object withoutType( return delegate.execute(type, value); } - @Specialization(guards = {"types.hasType(value)", "!interop.isNumber(value)"}) + @Specialization(guards = {"isWithType(value, types, interop)"}) Object doType( Object value, @Shared("interop") @CachedLibrary(limit = "3") InteropLibrary interop, diff --git a/test/Base_Tests/src/Semantic/Meta_Spec.enso b/test/Base_Tests/src/Semantic/Meta_Spec.enso index 9714a3882d9e..0f9dd416abf5 100644 --- a/test/Base_Tests/src/Semantic/Meta_Spec.enso +++ b/test/Base_Tests/src/Semantic/Meta_Spec.enso @@ -52,6 +52,21 @@ type Sum_Type Variant_A x Variant_B y +type R + private V a:Text i:Integer + + as_text self = self:Text + as_int_text self = + r = (self : Integer & Text) + r + as_text_int self = + r = (self : Text & Integer) + r + as_int self = self:Integer + +Text.from (that:R) = that.a +Integer.from (that:R) = that.i + add_specs suite_builder = suite_builder.group "Meta-Value Manipulation" group_builder-> group_builder.specify "should allow manipulating unresolved symbols" <| @@ -209,6 +224,24 @@ add_specs suite_builder = e_tpe . should_equal_type IOException e_tpe . should_not_equal_type JException + group_builder.specify "multi_value_as_text" <| + v = R.V "hi" 3 . as_text + Meta.type_of v . should_equal Text + + group_builder.specify "multi_value_as_int" <| + v = R.V "hi" 3 . as_int + Meta.type_of v . should_equal Integer + + group_builder.specify "multi_value_as_text_int" <| + v = R.V "hi" 3 . as_text_int + Meta.type_of v . should_equal Text + v.is_a Text . should_be_true + + group_builder.specify "multi_value_as_int_text" <| + v = R.V "hi" 3 . as_int_text + Meta.type_of v . should_equal Integer + v.is_a Integer . should_be_true + group_builder.specify "constructors of Boolean" <| typ = Boolean