Convert constants to Enso values (#8416)

This commit is contained in:
Jaroslav Tulach 2023-11-29 14:57:45 +01:00 committed by GitHub
parent 5216b8c0cb
commit f1cd51ab6c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 1 deletions

View File

@ -80,6 +80,7 @@ import org.enso.interpreter.node.expression.atom.{
ConstantNode, ConstantNode,
QualifiedAccessorNode QualifiedAccessorNode
} }
import org.enso.interpreter.node.expression.builtin.interop.syntax.HostValueToEnsoNode
import org.enso.interpreter.node.expression.builtin.BuiltinRootNode import org.enso.interpreter.node.expression.builtin.BuiltinRootNode
import org.enso.interpreter.node.expression.constant._ import org.enso.interpreter.node.expression.constant._
import org.enso.interpreter.node.expression.foreign.ForeignMethodCallNode import org.enso.interpreter.node.expression.foreign.ForeignMethodCallNode
@ -1375,7 +1376,10 @@ class IrToTruffle(
BadPatternMatch.NonConstantPolyglotSymbol(symbol) BadPatternMatch.NonConstantPolyglotSymbol(symbol)
) )
} else { } else {
Right(iop.readMember(polyClass, symbol)) val value = iop.readMember(polyClass, symbol);
val ensoValue =
HostValueToEnsoNode.getUncached().execute(value)
Right(ensoValue)
} }
} }
} catch { } catch {

View File

@ -7,6 +7,8 @@ import java.util.function.Function;
public class TestClass { public class TestClass {
public static final int FINAL_ONE = 1; public static final int FINAL_ONE = 1;
public static int nonFinalTwo = 2; public static int nonFinalTwo = 2;
public static final short SHORT_ONE = 3;
public static final long LONG_ONE = 4;
private final Function<Long, Long> function; private final Function<Long, Long> function;

View File

@ -139,6 +139,26 @@ public class JavaInteropTest extends TestBase {
assertEquals("Compile error: nonFinalTwo is not a constant.", e.getMessage()); assertEquals("Compile error: nonFinalTwo is not a constant.", e.getMessage());
} }
} }
@Test
public void testShortConstant() {
var code = """
from Standard.Base import IO
polyglot java import org.enso.example.TestClass
to_string x = case x of
TestClass.FINAL_ONE -> "int"
TestClass.SHORT_ONE -> "short"
TestClass.LONG_ONE -> "long"
_ -> "none"
main =
IO.println <| to_string 1
IO.println <| to_string 2
IO.println <| to_string 3
IO.println <| to_string 4
""";
checkPrint(code, List.of("int", "none", "short", "long"));
}
@Test @Test
public void testImportOuterClassAndReferenceInner() { public void testImportOuterClassAndReferenceInner() {