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

Ensure EnsoMultiValue returns some Meta.type_of #11480

Merged
merged 1 commit into from
Nov 4, 2024
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -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
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't you also add test for Meta.type_of v . should_equal Integer ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I cannot right now, as the type doesn't equal Integer. Currently only the first type is used by type_of. That's likely to change with the work on

For now, the test checks just the first type.

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
Loading