From a083a37ee58dc48d92cf2b844466a295eb3e643e Mon Sep 17 00:00:00 2001 From: Yong He Date: Wed, 10 Aug 2022 15:37:19 -0700 Subject: Add `none` literal that is convertible to `Optional`. (#2356) * Add `none` literal that is convertible to `Optional`. * Fix cpu code gen. * Include vk and cpu test for is-as operator test. * Inline comparison operators. Co-authored-by: Yong He --- source/slang/slang-check-conversion.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'source/slang/slang-check-conversion.cpp') diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp index 6290acbd9..4bcf07b2b 100644 --- a/source/slang/slang-check-conversion.cpp +++ b/source/slang/slang-check-conversion.cpp @@ -773,13 +773,28 @@ namespace Slang { if (outCost) { - *outCost = kConversionCost_None; + *outCost = kConversionCost_NullPtrToPtr; } if (outToExpr) *outToExpr = fromExpr; return true; } - + // none_t can be cast into any Optional type. + if (as(fromType) && as(toType)) + { + if (outCost) + { + *outCost = kConversionCost_NoneToOptional; + } + if (outToExpr) + { + auto resultExpr = getASTBuilder()->create(); + resultExpr->loc = fromExpr->loc; + resultExpr->type = toType; + *outToExpr = resultExpr; + } + return true; + } // If we are casting to an interface type, then that will succeed // if the "from" type conforms to the interface. // -- cgit v1.2.3