Skip to content

Commit 95f052b

Browse files
committed
Cleaner SemanticsDeclHeaderVisitor::validateGenericConstraintSubType
- #8445 (comment)
1 parent 25801cd commit 95f052b

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

source/slang/slang-check-decl.cpp

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ struct SemanticsDeclHeaderVisitor : public SemanticsDeclVisitorBase,
372372
bool validateGenericConstraintSubType(
373373
GenericTypeConstraintDecl* decl,
374374
TypeExp type,
375-
bool diagnose);
375+
DiagnosticSink* sink = nullptr);
376376

377377
void checkForwardReferencesInGenericConstraint(GenericTypeConstraintDecl* decl);
378378

@@ -3256,7 +3256,7 @@ bool isProperConstraineeType(Type* type)
32563256
bool SemanticsDeclHeaderVisitor::validateGenericConstraintSubType(
32573257
GenericTypeConstraintDecl* decl,
32583258
TypeExp type,
3259-
bool diagnose)
3259+
DiagnosticSink* sink)
32603260
{
32613261
// Validate that the sub type of a constraint is in valid form.
32623262
//
@@ -3276,8 +3276,8 @@ bool SemanticsDeclHeaderVisitor::validateGenericConstraintSubType(
32763276
auto dependentGeneric = getShared()->getDependentGenericParent(subDeclRef);
32773277
if (dependentGeneric.getDecl() != decl->parentDecl)
32783278
{
3279-
if (diagnose)
3280-
getSink()->diagnose(type.exp, Diagnostics::invalidConstraintSubType, type);
3279+
if (sink)
3280+
sink->diagnose(type.exp, Diagnostics::invalidConstraintSubType, type);
32813281
return false;
32823282
}
32833283
}
@@ -3296,8 +3296,8 @@ bool SemanticsDeclHeaderVisitor::validateGenericConstraintSubType(
32963296
auto lookupDeclRef = as<LookupDeclRef>(subDeclRef.declRefBase);
32973297
if (!lookupDeclRef)
32983298
{
3299-
if (diagnose)
3300-
getSink()->diagnose(type.exp, Diagnostics::invalidConstraintSubType, type);
3299+
if (sink)
3300+
sink->diagnose(type.exp, Diagnostics::invalidConstraintSubType, type);
33013301
return false;
33023302
}
33033303

@@ -3311,20 +3311,20 @@ bool SemanticsDeclHeaderVisitor::validateGenericConstraintSubType(
33113311
auto baseType = as<Type>(lookupDeclRef->getLookupSource());
33123312
if (!baseType)
33133313
{
3314-
if (diagnose)
3315-
getSink()->diagnose(type.exp, Diagnostics::invalidConstraintSubType, type);
3314+
if (sink)
3315+
sink->diagnose(type.exp, Diagnostics::invalidConstraintSubType, type);
33163316
return false;
33173317
}
33183318
type.type = baseType;
3319-
return validateGenericConstraintSubType(decl, type, diagnose);
3319+
return validateGenericConstraintSubType(decl, type, sink);
33203320
}
33213321
}
33223322
if (!isProperConstraineeType(type.type))
33233323
{
33243324
// It is meaningless for certain types to be used in type constraints.
33253325
// For example, `IFoo<T>` should not appear as the left-hand-side of a generic constraint.
3326-
if (diagnose)
3327-
getSink()->diagnose(type.exp, Diagnostics::invalidConstraintSubType, type);
3326+
if (sink)
3327+
sink->diagnose(type.exp, Diagnostics::invalidConstraintSubType, type);
33283328
return false;
33293329
}
33303330
return true;
@@ -3458,7 +3458,7 @@ void SemanticsDeclHeaderVisitor::visitGenericTypeConstraintDecl(GenericTypeConst
34583458
equalityCannon = checkGenericTypeEqualityCanonicalOrder(decl);
34593459
}
34603460

3461-
bool validSub = validateGenericConstraintSubType(decl, decl->sub, true);
3461+
bool validSub = validateGenericConstraintSubType(decl, decl->sub, getSink());
34623462
if (decl->isEqualityConstraint)
34633463
{
34643464
if (!validSub && !equalityCannon)
@@ -3493,8 +3493,8 @@ bool SemanticsDeclHeaderVisitor::checkGenericTypeEqualityCanonicalOrder(
34933493
{
34943494
auto compare = [&]() -> int
34953495
{
3496-
bool subOk = validateGenericConstraintSubType(decl, decl->sub, false);
3497-
bool supOk = validateGenericConstraintSubType(decl, decl->sup, false);
3496+
bool subOk = validateGenericConstraintSubType(decl, decl->sub);
3497+
bool supOk = validateGenericConstraintSubType(decl, decl->sup);
34983498

34993499
if (subOk != supOk) // Only one is qualified
35003500
{

0 commit comments

Comments
 (0)