From e036c7f38e3b8b1f0b0e0ac1b4ef22fc6f16963b Mon Sep 17 00:00:00 2001 From: ArielG-NV <159081215+ArielG-NV@users.noreply.github.com> Date: Tue, 8 Jul 2025 17:18:02 -0700 Subject: Fix `extension` incorrectly interacting with `equality` and `type-coercion` constraints (#7578) * fix problem * cleanup comment * format code * make change more restrictive * format code * push logic update * format code * push test fix * make test more general --------- Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com> --- source/slang/slang-check-constraint.cpp | 4 ++++ source/slang/slang-check-decl.cpp | 4 ++-- source/slang/slang-check-impl.h | 6 ++++++ 3 files changed, 12 insertions(+), 2 deletions(-) (limited to 'source') diff --git a/source/slang/slang-check-constraint.cpp b/source/slang/slang-check-constraint.cpp index 7c55c440c..7c6f8929a 100644 --- a/source/slang/slang-check-constraint.cpp +++ b/source/slang/slang-check-constraint.cpp @@ -363,6 +363,7 @@ DeclRef SemanticsVisitor::trySolveConstraintSystem( ValUnificationContext unificationContext; unificationContext.optionalConstraint = constraintDeclRef.getDecl()->hasModifier(); + unificationContext.equalityConstraint = constraintDeclRef.getDecl()->isEqualityConstraint; if (!TryUnifyTypes( *system, unificationContext, @@ -492,6 +493,8 @@ DeclRef SemanticsVisitor::trySolveConstraintSystem( { if (c.isOptional) joinType = type; + else if (c.isEquality) + joinType = type; else // failure! return DeclRef(); @@ -970,6 +973,7 @@ bool SemanticsVisitor::TryUnifyTypeParam( constraint.val = type; constraint.isUsedAsLValue = type.isLeftValue; constraint.isOptional = unificationContext.optionalConstraint; + constraint.isEquality = unificationContext.equalityConstraint; constraints.constraints.add(constraint); return true; diff --git a/source/slang/slang-check-decl.cpp b/source/slang/slang-check-decl.cpp index 558834c34..5de83e24d 100644 --- a/source/slang/slang-check-decl.cpp +++ b/source/slang/slang-check-decl.cpp @@ -3398,9 +3398,9 @@ void SemanticsDeclHeaderVisitor::visitGenericDecl(GenericDecl* genericDecl) ensureDecl(valParam, DeclCheckState::ReadyForReference); valParam->parameterIndex = parameterIndex++; } - else if (auto constraint = as(m)) + else if (as(m) || as(m)) { - ensureDecl(constraint, DeclCheckState::ReadyForReference); + ensureDecl(m, DeclCheckState::ReadyForReference); } } } diff --git a/source/slang/slang-check-impl.h b/source/slang/slang-check-impl.h index 30e317401..4a6ccfe17 100644 --- a/source/slang/slang-check-impl.h +++ b/source/slang/slang-check-impl.h @@ -2305,6 +2305,11 @@ public: // if it is otherwise unconstrained, but doesn't take precedence over a constraint that is // not optional. bool isOptional = false; + + // Is this constraint an equality? This tells us that "joining" types is meaningless, we + // know the result will be the sub type. If it is not, we will error once we start + // substituting types. + bool isEquality = false; }; // A collection of constraints that will need to be satisfied (solved) @@ -2658,6 +2663,7 @@ public: { Index indexInTypePack = 0; bool optionalConstraint = false; + bool equalityConstraint = false; }; // Try to find a unification for two values -- cgit v1.2.3