Skip to content

Commit

Permalink
Check if autoscoped constructor really produces Atom
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach committed Jun 6, 2024
1 parent 890cba4 commit ab0724c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import org.enso.interpreter.runtime.callable.function.Function;
import org.enso.interpreter.runtime.data.EnsoObject;
import org.enso.interpreter.runtime.data.Type;
import org.enso.interpreter.runtime.data.atom.Atom;
import org.enso.interpreter.runtime.data.atom.AtomConstructor;
import org.enso.interpreter.runtime.error.PanicException;
import org.enso.interpreter.runtime.library.dispatch.TypesLibrary;
import org.enso.interpreter.runtime.scope.ModuleScope;
import org.enso.interpreter.runtime.state.State;
Expand Down Expand Up @@ -235,7 +237,7 @@ Object instantiateUncached(
return invokeConstructor(c, unresolved.asPrototype(), unresolved, state, callNode);
}

private static Object invokeConstructor(
private Object invokeConstructor(
AtomConstructor c,
UnresolvedConstructor prototype,
UnresolvedConstructor unresolved,
Expand All @@ -254,7 +256,13 @@ private static Object invokeConstructor(
args[0] = fn;
var helper = Function.ArgumentsHelper.buildArguments(fn, null, state, args);
var r = callNode.call(helper);
return r;
if (r instanceof Atom) {
return r;
} else {
var ctx = EnsoContext.get(this);
var err = ctx.getBuiltins().error().makeTypeError(c.getType(), r, prototype.toString());
throw new PanicException(err, this);
}
}

private static Object checkSingleton(Type c, UnresolvedConstructor unresolved) {
Expand Down
15 changes: 15 additions & 0 deletions test/Base_Tests/src/Semantic/Conversion_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,21 @@ add_specs suite_builder =
foo = v:Foo
Foo.Value 10 . should_equal foo

group_builder.specify "Foo.Value constructor is not autoscoped" <|

v = ..Value
err = Test.expect_panic Type_Error <|
f = v:Foo
f

msg = err.to_text

msg . should_contain "Type error:"
msg . should_contain "Expected `..Value` to be Foo"
msg . should_contain "got Foo.Value["
msg . should_contain "foo=_"
msg . should_contain "Try to apply foo argument"

group_builder.specify "..False can be autoscoped" <|

bool b:Boolean = b
Expand Down

0 comments on commit ab0724c

Please sign in to comment.