Skip to content

Commit

Permalink
Allow ..Nothing to resolve to Nothing (#9746)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach authored Apr 22, 2024
1 parent fa6b7f8 commit 11dda5b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ Object instantiateCached(
@Cached("buildApplication(prototype)") DirectCallNode callNode,
@Cached("expectedType.getConstructors().get(prototype.getName())") AtomConstructor c) {
if (c == null) {
return null;
return checkSingleton(expectedType, unresolved);
} else {
return invokeConstructor(c, prototype, unresolved, state, callNode);
}
Expand All @@ -229,7 +229,7 @@ Object instantiateUncached(
MaterializedFrame frame, State state, Type expectedType, UnresolvedConstructor unresolved) {
var c = expectedType.getConstructors().get(unresolved.getName());
if (c == null) {
return null;
return checkSingleton(expectedType, unresolved);
}
var callNode = buildApplication(unresolved);
return invokeConstructor(c, unresolved.asPrototype(), unresolved, state, callNode);
Expand All @@ -249,6 +249,19 @@ private static Object invokeConstructor(
var r = callNode.call(helper);
return r;
}

private static Object checkSingleton(Type c, UnresolvedConstructor unresolved) {
if (!c.isEigenType()) {
return null;
} else {
return equalTypeAndConstructorName(c, unresolved) ? c : null;
}
}

@CompilerDirectives.TruffleBoundary
private static boolean equalTypeAndConstructorName(Type c, UnresolvedConstructor unresolved) {
return c.getName().equals(unresolved.getName());
}
}

@ExportMessage
Expand Down
5 changes: 5 additions & 0 deletions test/Base_Tests/src/Semantic/Conversion_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ add_specs suite_builder =

foo_vec vec . should_equal [3, 4, 5]

group_builder.specify "Autoscope Nothing" <|
accept (n:Nothing) = n

accept ..Nothing . is_nothing . should_be_true

suite_builder.group "Polyglot Argument" group_builder->
f1 (x : DateTimeFormatter) = x.to_text
f2 (x : Text | DateTimeFormatter) = case x of
Expand Down

0 comments on commit 11dda5b

Please sign in to comment.