Allow ..Nothing to resolve to Nothing (#9746)

This commit is contained in:
Jaroslav Tulach 2024-04-22 06:54:07 +02:00 committed by GitHub
parent fa6b7f859f
commit 11dda5b9bc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 20 additions and 2 deletions

View File

@ -217,7 +217,7 @@ public final class UnresolvedConstructor implements EnsoObject {
@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);
}
@ -229,7 +229,7 @@ public final class UnresolvedConstructor implements EnsoObject {
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);
@ -249,6 +249,19 @@ public final class UnresolvedConstructor implements EnsoObject {
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

View File

@ -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