Skip to content

Add test for ancestor/descendant type-equality constraints#10447

Open
cmarcelo wants to merge 1 commit intoshader-slang:masterfrom
cmarcelo:ancestor-descendant-type-equality-check
Open

Add test for ancestor/descendant type-equality constraints#10447
cmarcelo wants to merge 1 commit intoshader-slang:masterfrom
cmarcelo:ancestor-descendant-type-equality-check

Conversation

@cmarcelo
Copy link
Contributor

@cmarcelo cmarcelo commented Mar 9, 2026

Add a generics test that exercises equality constraints between nested types and their enclosing type:

  • Box == Box.Nested
  • Box.Nested == Box

Add a generics test that exercises equality constraints between
nested types and their enclosing type:
- Box<X> == Box<X>.Nested<X>
- Box<X>.Nested<X> == Box<X>
@cmarcelo cmarcelo requested a review from a team as a code owner March 9, 2026 00:43
@cmarcelo cmarcelo requested review from bmillsNV and Copilot and removed request for a team March 9, 2026 00:43
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 9, 2026

📝 Walkthrough

Walkthrough

A new test file is added to verify generic type equality constraints involving ancestor ordering. The test defines a generic struct with nested types and functions that enforce bidirectional type equality constraints, checking that expected constraint violations are properly detected.

Changes

Cohort / File(s) Summary
Test Addition
tests/language-feature/generics/type-equality-ancestor-ordering.slang
New test file for generic type equality constraints with ancestor ordering. Includes a generic Box<T> struct with nested Nested<U> type, two generic functions with opposing type equality constraints, and error validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A box within a box so grand,
Where types must equal, carefully planned,
Ancestors checked in every way,
Generic constraints come to play!
Tests now dance to prove it's tight,
Type equality shines so bright! ✨

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the main change: adding a test for ancestor/descendant type-equality constraints, which aligns with the new test file and its focus on type equality between nested types and their enclosing type.
Description check ✅ Passed The description is directly related to the changeset, providing specific details about the equality constraints being tested: Box == Box.Nested and vice versa, which matches the test file content.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/language-feature/generics/type-equality-ancestor-ordering.slang (1)

23-24: Make the two expected failures distinguishable.

These two CHECK_FAIL-DAG lines are identical, so the test can pass without proving that triggerA<int>() and triggerB<int>() each failed independently. Please anchor each expectation to its specific instantiation site, or split the two directions into separate tests.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 14f298e9-d2e6-4e08-af80-1317b32a8eba

📥 Commits

Reviewing files that changed from the base of the PR and between d138e76 and fdab38b.

📒 Files selected for processing (1)
  • tests/language-feature/generics/type-equality-ancestor-ordering.slang

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new Slang generics regression test to ensure type-equality constraints behave consistently when comparing an enclosing generic type with a nested generic type, regardless of operand order.

Changes:

  • Introduces a CHECK_FAIL-based test covering Box<X> == Box<X>.Nested<X> and the reversed constraint.
  • Verifies both instantiations emit the expected diagnostic.

@aidanfnv aidanfnv added the pr: non-breaking PRs without breaking changes label Mar 10, 2026
triggerB<int>();
}

//CHECK_FAIL-DAG: error 38029: type argument 'Box<int>.Nested<int>' does not conform to the required interface 'Box<int>'
Copy link
Contributor

@aidanfnv aidanfnv Mar 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please update these checks to use the new diagnostics format. The format of these diagnostics has recently been changed, so these checks will now fail the CI tests until they are updated to the new format.

Please see https://github.com/shader-slang/slang/blob/master/docs/diagnostics.md for an explanation of the new format, and (more importantly for this case) https://github.com/shader-slang/slang/blob/master/docs/diagnostics.md#matching-fields for how to check the diagnostics in the new format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr: non-breaking PRs without breaking changes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants