From 7c56cc86dbb2cb62a67b02aef83265d29fbac16c Mon Sep 17 00:00:00 2001 From: Ahmad Rezaii Date: Mon, 23 Sep 2024 22:03:19 -0600 Subject: [PATCH] allow instantiation of _nil actuals for nilable class formals Signed-off-by: Ahmad Rezaii --- frontend/lib/resolution/can-pass.cpp | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/frontend/lib/resolution/can-pass.cpp b/frontend/lib/resolution/can-pass.cpp index 5ae403be740..cad138e614f 100644 --- a/frontend/lib/resolution/can-pass.cpp +++ b/frontend/lib/resolution/can-pass.cpp @@ -877,6 +877,18 @@ CanPassResult CanPassResult::canInstantiate(Context* context, return instantiate(); } + // TODO: Should we move this to the section below and have it call canPassSubtypeOrBorrowing? + // TODO: There may be cases for nilType that are not covered + // this is to allow instantiating 'class?' type with nil + if (auto cls = formalT->toClassType()) { + if (auto mt = cls->manageableType()) { + if (mt->isAnyClassType()) { + if (cls->decorator().isNilable() && actualT->isNilType()) + return instantiate(); + } + } + } + // TODO: check for constrained generic types if (auto actualCt = actualT->toClassType()) {