mirror of
https://github.com/enso-org/enso.git
synced 2024-11-27 05:15:42 +03:00
Convert constants to Enso values (#8416)
This commit is contained in:
parent
5216b8c0cb
commit
f1cd51ab6c
@ -80,6 +80,7 @@ import org.enso.interpreter.node.expression.atom.{
|
||||
ConstantNode,
|
||||
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.constant._
|
||||
import org.enso.interpreter.node.expression.foreign.ForeignMethodCallNode
|
||||
@ -1375,7 +1376,10 @@ class IrToTruffle(
|
||||
BadPatternMatch.NonConstantPolyglotSymbol(symbol)
|
||||
)
|
||||
} else {
|
||||
Right(iop.readMember(polyClass, symbol))
|
||||
val value = iop.readMember(polyClass, symbol);
|
||||
val ensoValue =
|
||||
HostValueToEnsoNode.getUncached().execute(value)
|
||||
Right(ensoValue)
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
|
@ -7,6 +7,8 @@ import java.util.function.Function;
|
||||
public class TestClass {
|
||||
public static final int FINAL_ONE = 1;
|
||||
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;
|
||||
|
||||
|
@ -139,6 +139,26 @@ public class JavaInteropTest extends TestBase {
|
||||
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
|
||||
public void testImportOuterClassAndReferenceInner() {
|
||||
|
Loading…
Reference in New Issue
Block a user