diff options
| author | Yong He <yonghe@outlook.com> | 2024-07-26 19:42:15 -0700 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-07-26 19:42:15 -0700 |
| commit | 7e2bc8e06f61d554bae9bbebc1db0302eb3f1d8a (patch) | |
| tree | 0f10e4a45cb81af2908da61743a4518de27748e2 /source/slang/slang-check-conversion.cpp | |
| parent | c0bff66541302309ff4833e8d4ae2eba1561498a (diff) | |
Allow passing sized array to unsized array parameter. (#4744)
Diffstat (limited to 'source/slang/slang-check-conversion.cpp')
| -rw-r--r-- | source/slang/slang-check-conversion.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
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<ArrayExpressionType>(fromType)) + { + if (auto toArrayType = as<ArrayExpressionType>(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 |
