summaryrefslogtreecommitdiff
path: root/source/slang/slang-check-conversion.cpp
diff options
context:
space:
mode:
authorSruthik P <spatibandlla@nvidia.com>2025-05-13 11:09:23 +0530
committerGitHub <noreply@github.com>2025-05-13 05:39:23 +0000
commit6c262bc5c9a364cd8c6a4026dbb9f8034c500f11 (patch)
treeacc5a5faa3d32aa59ff0277bf62e2e1e2de09716 /source/slang/slang-check-conversion.cpp
parent2fb95f99c3efbe54f92f6338ab8c6970f1ec35ee (diff)
Support Array Sizes using Generic arguments to be initialized via {} (#6720)
* Add support for Array Sizes using Generic arguments to be initialized via {} Fixes one subissue of #6138 This change adds support for initializing Arrays with Generic size arguments via {} and adds a test to verify it. The change checks for an array whose size parameter is a GenericParamIntVal and since the size of such an array will be known at link time, is not considered as a case of the size not being known statically. * Add support for Array Sizes using Generic arguments to be initialized via {} Fixes one subissue of #6138. Fixes the issue #6958. This change adds support for initializing Arrays with Generic size arguments via {} and adds a test to verify it. Support is added by means of adding a new AST Expr node that lowers down to the IR MakeArrayFromElement and the emission of a diagnostic is replaced with the creation of this new AST Expr node. * format code --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> Co-authored-by: Ellie Hermaszewska <ellieh@nvidia.com>
Diffstat (limited to 'source/slang/slang-check-conversion.cpp')
-rw-r--r--source/slang/slang-check-conversion.cpp18
1 files changed, 6 insertions, 12 deletions
diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp
index 1c8846e66..a2cb0f91b 100644
--- a/source/slang/slang-check-conversion.cpp
+++ b/source/slang/slang-check-conversion.cpp
@@ -613,19 +613,13 @@ bool SemanticsVisitor::_readAggregateValueFromInitializerList(
}
else
{
- // We don't know the element count statically,
- // so what are we supposed to be doing?
- //
- if (outToExpr)
- {
- getSink()->diagnose(
- fromInitializerListExpr,
- Diagnostics::cannotUseInitializerListForArrayOfUnknownSize,
- toElementCount);
- }
- return false;
- }
+ auto toMakeArrayFromElementExpr = m_astBuilder->create<MakeArrayFromElementExpr>();
+ toMakeArrayFromElementExpr->loc = fromInitializerListExpr->loc;
+ toMakeArrayFromElementExpr->type = QualType(toType);
+ *outToExpr = toMakeArrayFromElementExpr;
+ return true;
+ }
for (UInt ee = 0; ee < elementCount; ++ee)
{
Expr* coercedArg = nullptr;