From 7e2bc8e06f61d554bae9bbebc1db0302eb3f1d8a Mon Sep 17 00:00:00 2001 From: Yong He Date: Fri, 26 Jul 2024 19:42:15 -0700 Subject: Allow passing sized array to unsized array parameter. (#4744) --- source/slang/slang-check-conversion.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (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 00625d5f4..fafefa9dd 100644 --- a/source/slang/slang-check-conversion.cpp +++ b/source/slang/slang-check-conversion.cpp @@ -750,6 +750,31 @@ namespace Slang return true; } + // Allow implicit conversion from sized array to unsized array when + // calling a function. + // Note: we implement the logic here instead of an implicit_conversion + // intrinsic in the stdlib because we only want to allow this conversion + // when calling a function. + // + if (site == CoercionSite::Argument) + { + if (auto fromArrayType = as(fromType)) + { + if (auto toArrayType = as(toType)) + { + if (fromArrayType->getElementType()->equals(toArrayType->getElementType()) + && toArrayType->isUnsized()) + { + if (outToExpr) + *outToExpr = fromExpr; + if (outCost) + *outCost = kConversionCost_SizedArrayToUnsizedArray; + return true; + } + } + } + } + // Another important case is when either the "to" or "from" type // represents an error. In such a case we must have already // reporeted the error, so it is better to allow the conversion -- cgit v1.2.3