Skip to content

Commit

Permalink
Ensure EnsoMultiValue returns some Meta.type_of (#11480)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach authored Nov 4, 2024
1 parent 2b3bd2c commit dd107e0
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand Down
33 changes: 33 additions & 0 deletions test/Base_Tests/src/Semantic/Meta_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -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" <|
Expand Down Expand Up @@ -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

Expand Down

0 comments on commit dd107e0

Please sign in to comment.