diff --git a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConstructor.java b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConstructor.java index c2084cf5c2df..29bff7ae2306 100644 --- a/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConstructor.java +++ b/engine/runtime/src/main/java/org/enso/interpreter/runtime/callable/UnresolvedConstructor.java @@ -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; @@ -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, @@ -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) { diff --git a/test/Base_Tests/src/Semantic/Conversion_Spec.enso b/test/Base_Tests/src/Semantic/Conversion_Spec.enso index 43e9f5345d8e..b42d5bd14263 100644 --- a/test/Base_Tests/src/Semantic/Conversion_Spec.enso +++ b/test/Base_Tests/src/Semantic/Conversion_Spec.enso @@ -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