summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/slang/slang-check-constraint.cpp40
1 files changed, 17 insertions, 23 deletions
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<IntVal>(fst))
+ const auto fstInt = as<IntVal>(fst);
+ const auto sndInt = as<IntVal>(snd);
+ if (fstInt && sndInt)
{
- if (auto tc = as<TypeCastIntVal>(fstInt))
- fstInt = as<IntVal>(tc->getBase());
- if (auto sndInt = as<IntVal>(snd))
- {
- if (auto tc = as<TypeCastIntVal>(sndInt))
- sndInt = as<IntVal>(tc->getBase());
- auto fstParam = as<GenericParamIntVal>(fstInt);
- auto sndParam = as<GenericParamIntVal>(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<TypeCastIntVal>(i))
+ i = as<IntVal>(c->getBase());
+ return as<GenericParamIntVal>(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<DeclaredSubtypeWitness>(fst))