Skip to content
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 @@ -111,11 +111,7 @@ type DuckDB_Type_Mapping
Types.TIMESTAMP -> Value_Type.Date_Time False
Types.BLOB -> Value_Type.Binary Nothing False
Types.BIT -> Value_Type.Binary Nothing False
_ -> case sql_type.name of
"TIMESTAMP_NS" -> Value_Type.Date_Time False
"TIMESTAMPTZ" -> Value_Type.Date_Time True
"TIMESTAMP WITH TIME ZONE" -> Value_Type.Date_Time True
_ -> Value_Type.Unsupported_Data_Type sql_type.name sql_type
_ -> Value_Type.Unsupported_Data_Type sql_type.name sql_type

## ---
private: true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package org.enso.example;

public class TestConstants {
private TestConstants() {}

public static final int A = 1;
public static final int B = 2020;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.enso.interpreter.test;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertEquals;

import org.enso.interpreter.runtime.data.EnsoMultiValue;
Expand Down Expand Up @@ -55,4 +57,40 @@ private void doCaseOfBoolean(Object t, Object f) {
var two = choose.execute(f);
assertEquals("With " + f + " we should get 2", 2, two.asInt());
}

/** See <a href="https://github.com/enso-org/enso/issues/14426">#14426</a>. */
@Test
public void caseOfJavaFinalFields_SmallInteger() {
var code =
"""
polyglot java import org.enso.example.TestConstants

main =
x = 1
case x of
TestConstants.A -> "A"
_ -> "Unknown"
""";
var res = ctxRule.evalModule(code);
assertThat(res.isString(), is(true));
assertThat(res.asString(), is("A"));
}

/** See <a href="https://github.com/enso-org/enso/issues/14426">#14426</a>. */
@Test
public void caseOfJavaFinalFields_BiggerInteger() {
var code =
"""
polyglot java import org.enso.example.TestConstants

main =
x = 2020
case x of
TestConstants.B -> "B"
_ -> "Unknown"
""";
var res = ctxRule.evalModule(code);
assertThat(res.isString(), is(true));
assertThat(res.asString(), is("B"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ boolean isSameDouble(double left, double right) {
}
}

@Specialization
boolean isSameLong(long left, long right) {
Copy link
Member

Choose a reason for hiding this comment

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

This looks like the right specialization.

return left == right;
}

@Specialization(
guards = {
"interop.isString(left)",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.enso.base_test_helpers;

public class Constants {
private Constants() {}

public static final int SMALL_INT = 1;
public static final int BIG_INT = 2020;
public static final long SMALL_LONG = 2L;
public static final long BIG_LONG = 20_000L;
public static final String STRING = "string";
}
18 changes: 18 additions & 0 deletions test/Base_Tests/src/Semantic/Case_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Standard.Base.Data.Array as Array_Module
import Standard.Base.Data.Text as Text_Module
import Standard.Base.Data.Vector as Vector_Module

polyglot java import org.enso.base_test_helpers.Constants as Java_Constants
polyglot java import java.lang.Class
polyglot java import java.lang.Long as Java_Long
polyglot java import java.lang.Object as Java_Object
Expand Down Expand Up @@ -347,6 +348,23 @@ add_specs suite_builder = suite_builder.group "Pattern Matches" group_builder->
_ : Function -> Nothing
_ -> Test.fail "Expected to match on Function type."

group_builder.specify "should pattern match on Java constant fields" <|
case 1 of
Java_Constants.SMALL_INT -> Nothing
_ -> Test.fail "Expected to match on SMALL_INT."
case "string" of
Java_Constants.STRING -> Nothing
_ -> Test.fail "Expected to match on STRING."
case 2 of
Java_Constants.SMALL_LONG -> Nothing
_ -> Test.fail "Expected to match on SMALL_LONG."
case 20000 of
Java_Constants.BIG_LONG -> Nothing
_ -> Test.fail "Expected to match on BIG_LONG."
case 2020 of
Java_Constants.BIG_INT -> Nothing
_ -> Test.fail "Expected to match on BIG_INT."

main filter=Nothing =
suite = Test.build suite_builder->
add_specs suite_builder
Expand Down