From d655302465457c5d3285ae5339201a0769cc38dc Mon Sep 17 00:00:00 2001 From: Yong He Date: Thu, 5 Sep 2024 11:24:19 -0700 Subject: Support `where` clause and type equality constraint. (#4986) * Support `where` clause. * Fix. * Fix parser. * Enhance test to cover traditional __generic syntax. * Update user-guide. * Support `where` clause on associatedtype. * Fix. * Put in more comments. --- source/slang/slang-check-conversion.cpp | 16 ++++++++++++++++ 1 file changed, 16 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 85040dc55..c0d7feaff 100644 --- a/source/slang/slang-check-conversion.cpp +++ b/source/slang/slang-check-conversion.cpp @@ -1019,6 +1019,22 @@ namespace Slang *outCost = kConversionCost_CastToInterface; return true; } + else if (auto fromIsToWitness = tryGetSubtypeWitness(toType, fromType)) + { + // Is toType and fromType the same via some type equality witness? + // If so there is no need to do any conversion. + // + if (isTypeEqualityWitness(fromIsToWitness)) + { + if (outToExpr) + { + *outToExpr = createCastToSuperTypeExpr(toType, fromExpr, fromIsToWitness); + } + if (outCost) + *outCost = 0; + return true; + } + } // Disallow converting to a ParameterGroupType. // -- cgit v1.2.3