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

Avoid null values in constant node #8061

Merged
merged 2 commits into from
Oct 16, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -2,6 +2,7 @@

import com.oracle.truffle.api.frame.VirtualFrame;
import com.oracle.truffle.api.nodes.NodeInfo;
import java.util.Objects;
import org.enso.interpreter.node.ExpressionNode;

/** Represents a compile-time constant. */
Expand All @@ -10,7 +11,7 @@ public class ConstantObjectNode extends ExpressionNode {
private final Object object;

private ConstantObjectNode(Object object) {
this.object = object;
this.object = Objects.requireNonNull(object);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1678,19 +1678,28 @@ class IrToTruffle(
module.unsafeAsModule().getScope.getAssociatedType
)
case BindingsMap.ResolvedPolyglotSymbol(module, symbol) =>
ConstantObjectNode.build(
module
.unsafeAsModule()
.getScope
.getPolyglotSymbol(symbol.name)
)
val s = module
.unsafeAsModule()
.getScope
.getPolyglotSymbol(symbol.name)
if (s == null) {
throw new CompilerError(
s"No polyglot symbol for ${symbol.name}"
)
}
ConstantObjectNode.build(s)
case BindingsMap.ResolvedPolyglotField(symbol, name) =>
ConstantObjectNode.build(
symbol.module
.unsafeAsModule()
.getScope
.getPolyglotSymbol(name)
)
val s = symbol.module
.unsafeAsModule()
.getScope
.getPolyglotSymbol(name)
if (s == null) {
throw new CompilerError(
s"No polyglot symbol for ${name}"
JaroslavTulach marked this conversation as resolved.
Show resolved Hide resolved
)
}

ConstantObjectNode.build(s)
case BindingsMap.ResolvedMethod(_, method) =>
throw new CompilerError(
s"Impossible here, ${method.name} should be caught when translating application"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -137,4 +137,47 @@ public void testInvalidEnsoProjectRef() throws Exception {
var err = run.execute(0);
assertEquals("Error: Module is not a part of a package.", err.asString());
}

@Test
public void testDoubledRandom() throws Exception {
var module =
ctx.eval(
"enso",
"""
from Standard.Base import all
polyglot java import java.util.Random

run seed =
operator1 = Random.new seed
""");
var run = module.invokeMember("eval_expression", "run");
try {
var err = run.execute(1L);
fail("Not expecting any result: " + err);
} catch (PolyglotException ex) {
assertEquals("Compile error: Compiler Internal Error: No polyglot symbol for Random.", ex.getMessage());
}
}

@Test
public void testUnknownStaticField() throws Exception {
var module =
ctx.eval(
"enso",
"""
from Standard.Base import all
polyglot java import java.util.Random as R

run seed = case seed of
R.NO_FIELD -> 0
_ -> -1
""");
var run = module.invokeMember("eval_expression", "run");
try {
var err = run.execute(1L);
fail("Not expecting any result: " + err);
} catch (PolyglotException ex) {
assertEquals("Compile error: NO_FIELD is not visible in this scope.", ex.getMessage());
}
}
}