From 94b2c676662ef581b5de3baa6cde076fe07ef26b Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Sat, 11 Feb 2023 13:57:35 +0800 Subject: Take into account existing initializer list type when performing coercions (#2641) Fixes https://github.com/shader-slang/slang/issues/2189 --- source/slang/slang-check-conversion.cpp | 11 +++++++++++ 1 file changed, 11 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 71231b9e5..abfe7afa0 100644 --- a/source/slang/slang-check-conversion.cpp +++ b/source/slang/slang-check-conversion.cpp @@ -502,6 +502,17 @@ namespace Slang // TODO: we should handle the special case of `{0}` as an initializer // for arbitrary `struct` types here. + // If this initializer list has a more specific type than just + // InitializerListType (i.e. it's already undergone a coercion) we + // should ensure that we're allowed to coerce from that type to our + // desired type. + // If this isn't prohibited, then we can proceed to try and coerce from + // the initializer list itself; assuming that coercion is closed under + // composition this shouldn't fail. + if(!as(fromInitializerListExpr->type) && + !canCoerce(toType, fromInitializerListExpr->type, nullptr)) + return _failedCoercion(toType, outToExpr, fromInitializerListExpr); + if(!_readAggregateValueFromInitializerList(toType, outToExpr, fromInitializerListExpr, argIndex)) return false; -- cgit v1.2.3