From 24f8999c892a9c4d108616c08d714e8dea562707 Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 11 Jul 2024 16:12:41 -0700 Subject: Fix incorrect codegen when returning initializer list as existential value. (#4618) * Add `dev` cmake preset. * Fix incorrect codegen when returning initializer list as existential value. * Fix cmake. * Fixup. --- source/slang/slang-check-conversion.cpp | 41 ++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 19 deletions(-) (limited to 'source') diff --git a/source/slang/slang-check-conversion.cpp b/source/slang/slang-check-conversion.cpp index 16f413055..111f4e465 100644 --- a/source/slang/slang-check-conversion.cpp +++ b/source/slang/slang-check-conversion.cpp @@ -842,29 +842,32 @@ namespace Slang // Coercion from an initializer list is allowed for many types, // so we will farm that out to its own subroutine. // - if( auto fromInitializerListExpr = as(fromExpr)) + if (fromExpr && as(fromExpr->type.type)) { - if( !_coerceInitializerList( - toType, - outToExpr, - fromInitializerListExpr) ) + if (auto fromInitializerListExpr = as(fromExpr)) { - return false; - } + if (!_coerceInitializerList( + toType, + outToExpr, + fromInitializerListExpr)) + { + return false; + } - // For now, we treat coercion from an initializer list - // as having no cost, so that all conversions from initializer - // lists are equally valid. This is fine given where initializer - // lists are allowed to appear now, but might need to be made - // more strict if we allow for initializer lists in more - // places in the language (e.g., as function arguments). - // - if(outCost) - { - *outCost = kConversionCost_None; - } + // For now, we treat coercion from an initializer list + // as having no cost, so that all conversions from initializer + // lists are equally valid. This is fine given where initializer + // lists are allowed to appear now, but might need to be made + // more strict if we allow for initializer lists in more + // places in the language (e.g., as function arguments). + // + if (outCost) + { + *outCost = kConversionCost_None; + } - return true; + return true; + } } // nullptr_t can be cast into any pointer type. -- cgit v1.2.3