summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-conversion.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-check-conversion.cpp')
-rw-r--r--source/slang/slang-check-conversion.cpp19
1 files changed, 17 insertions, 2 deletions
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<T> type.
+ if (as<NoneType>(fromType) && as<OptionalType>(toType))
+ {
+ if (outCost)
+ {
+ *outCost = kConversionCost_NoneToOptional;
+ }
+ if (outToExpr)
+ {
+ auto resultExpr = getASTBuilder()->create<MakeOptionalExpr>();
+ 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.
//