From cdd5e6666f98903d61118ada5cba51424fd1577c Mon Sep 17 00:00:00 2001 From: Ellie Hermaszewska Date: Wed, 23 Aug 2023 17:29:25 +0800 Subject: Retain int casts when unifying generic params (#3145) --- source/slang/slang-check-constraint.cpp | 40 ++++++++++++++------------------- 1 file changed, 17 insertions(+), 23 deletions(-) (limited to 'source') diff --git a/source/slang/slang-check-constraint.cpp b/source/slang/slang-check-constraint.cpp index e7eccfaec..6e600c4af 100644 --- a/source/slang/slang-check-constraint.cpp +++ b/source/slang/slang-check-constraint.cpp @@ -526,30 +526,24 @@ namespace Slang } // Check if both are integer values in general - if (auto fstInt = as(fst)) + const auto fstInt = as(fst); + const auto sndInt = as(snd); + if (fstInt && sndInt) { - if (auto tc = as(fstInt)) - fstInt = as(tc->getBase()); - if (auto sndInt = as(snd)) - { - if (auto tc = as(sndInt)) - sndInt = as(tc->getBase()); - auto fstParam = as(fstInt); - auto sndParam = as(sndInt); - - bool okay = false; - if (fstParam) - { - if(TryUnifyIntParam(constraints, fstParam->getDeclRef(), sndInt)) - okay = true; - } - if (sndParam) - { - if(TryUnifyIntParam(constraints, sndParam->getDeclRef(), fstInt)) - okay = true; - } - return okay; - } + const auto paramUnderCast = [](IntVal* i){ + if(const auto c = as(i)) + i = as(c->getBase()); + return as(i); + }; + auto fstParam = paramUnderCast(fstInt); + auto sndParam = paramUnderCast(sndInt); + + bool okay = false; + if (fstParam) + okay |= TryUnifyIntParam(constraints, fstParam->getDeclRef(), sndInt); + if (sndParam) + okay |= TryUnifyIntParam(constraints, sndParam->getDeclRef(), fstInt); + return okay; } if (auto fstWit = as(fst)) -- cgit v1.2.3