Skip to content

fix: FilterVisibility now applies visibility filter to inherited types (extends)#11043

Draft
Copilot wants to merge 6 commits into
mainfrom
copilot/bug-fix-filter-visibility
Draft

fix: FilterVisibility now applies visibility filter to inherited types (extends)#11043
Copilot wants to merge 6 commits into
mainfrom
copilot/bug-fix-filter-visibility

Conversation

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

FilterVisibility only filtered properties directly on a model but ignored baseModel, so inherited properties with incompatible visibility passed through unfiltered.

model Base {
  @visibility(Lifecycle.Read) id: string;
}

model User extends Base {
  name: string;
}

// Previously: UserCreate still inherited unfiltered Base with `id` visible
// Now: Base is also filtered, producing BaseCreate with `id` removed
model UserCreate is FilterVisibility<User, #{ all: #[Lifecycle.Create] }, "{name}Create">;

Changes

  • packages/compiler/src/lib/visibility.ts — In createVisibilityFilterMutator's Model.replace handler, recursively apply the visibility filter mutator to model.baseModel when present
  • packages/compiler/test/visibility.test.ts — Added test cases covering:
    • Multi-level inheritance where all base types have filtered properties
    • Base model unchanged when it has no visibility-restricted properties
    • Entire base chain unchanged when only the leaf has filtered properties
    • Intermediate types renamed when their deeper base is transformed
    • Direct applyVisibilityFilter API with inheritance
    • Self-referential model (e.g., next?: LinkedNode) does not produce infinite regress

…s (extends)

When filtering a model by visibility, the filter is now also applied to
base models in the inheritance chain. This ensures that properties with
incompatible visibility in base types are properly filtered out.

Closes #11036

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
@microsoft-github-policy-service microsoft-github-policy-service Bot added the compiler:core Issues for @typespec/compiler label Jun 22, 2026
Copilot AI changed the title [WIP] Fix FilterVisibility to honor extends fix: FilterVisibility now applies visibility filter to inherited types (extends) Jun 22, 2026
Copilot AI requested a review from markcowl June 22, 2026 18:41

@markcowl markcowl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot Please pull the latest from main, make the suggested changes, ensure all tests pass and all files are formatted correctly. Ensure that only changes associated with this PR are in the pr diff

ok(!arrA.properties.has("invisible"));
});

it("applies visibility filter to base model (extends)", async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Ensure that there is a test over a self referential model, for example, if some type ihas s efl link, it should not produce infinite regress.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added a test for a self-referential model (LinkedNode with next?: LinkedNode property) that verifies no infinite regress occurs. The cachedMutateSubgraph cache and the internal seen map in mutateSubgraphWorker prevent infinite recursion. Commit: a7de7ad.

Copilot AI and others added 2 commits June 22, 2026 20:46
…r-visibility

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please pull the latest from main, make the suggested changes, ensure all tests pass and all files are formatted correctly. Ensure that only changes associated with this PR are in the pr diff

Done — merged latest from main, added the self-referential model test, verified all 61 visibility tests pass, and confirmed formatting is correct. The diff only contains the 3 expected files.

Copilot AI requested a review from markcowl June 22, 2026 20:53

@markcowl markcowl left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@copilot Please pull the latest from main, make the suggested update, ensure all tests pass, all files are correctly formatted, and only the changes associated with thios PR are in the pr diff

ok(!baseFiltered.properties.has("id"));
});

it("does not produce infinite regress for self-referential models", async () => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Not quite what I meant. Here I mean a test in which the target test model extends a model that has a self-referential property.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated the test so Child extends LinkedNode where LinkedNode has next?: LinkedNode. This verifies the visibility filter correctly handles the base model's self-referential property without infinite regress. Commit: 1e6c9a4.

Copilot AI and others added 2 commits June 22, 2026 23:05
…r-visibility

Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>
Co-authored-by: markcowl <1054056+markcowl@users.noreply.github.com>

Copilot AI commented Jun 22, 2026

Copy link
Copy Markdown
Contributor Author

@copilot Please pull the latest from main, make the suggested update, ensure all tests pass, all files are correctly formatted, and only the changes associated with thios PR are in the pr diff

Done — merged latest main, updated the self-referential test so the target model extends a base with a self-link property, all 61 visibility tests pass, formatting is correct, and the diff contains only the 3 expected files.

Copilot AI requested a review from markcowl June 22, 2026 23:08
@pkg-pr-new

pkg-pr-new Bot commented Jun 22, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@typespec/compiler@11043

commit: 1e6c9a4

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

Labels

compiler:core Issues for @typespec/compiler

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants