From dfdf243f07c977fa59b1a5968ce053bf590f8120 Mon Sep 17 00:00:00 2001 From: Yong He Date: Tue, 26 Mar 2024 17:35:24 -0700 Subject: Support mutable existential parameters. (#3836) * Support mutable existential parameters. * Update test. --- source/slang/slang-check-conversion.cpp | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (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 a2381c7f7..aeb964cc9 100644 --- a/source/slang/slang-check-conversion.cpp +++ b/source/slang/slang-check-conversion.cpp @@ -932,11 +932,15 @@ namespace Slang // to pass a value of a derived `struct` type into methods that // expect a value of its base type. // - // TODO: vet this logic for correctness. - // if (fromExpr && fromExpr->type.isLeftValue) { - (*outToExpr)->type.isLeftValue = true; + // If the original type is a concrete type and toType is an interface type, + // we need to wrap the original expression into a MakeExistential, and the + // result of MakeExistential is not an l-value. + bool toTypeIsInterface = isInterfaceType(toType); + bool fromTypeIsInterface = isInterfaceType(fromType); + if (!toTypeIsInterface || toTypeIsInterface == fromTypeIsInterface) + (*outToExpr)->type.isLeftValue = true; } } if (outCost) -- cgit v1.2.3