[http-client-csharp] Lazily resolve TypeProvider FQN in AddTypeToKeep to prevent stale namespace after visitor changes#10273
Draft
[http-client-csharp] Lazily resolve TypeProvider FQN in AddTypeToKeep to prevent stale namespace after visitor changes#10273
Conversation
…lution Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/f4a12cd1-5ba2-4c12-bd25-9ca2677634c7 Co-authored-by: haiyuazhang <1924967+haiyuazhang@users.noreply.github.com>
Agent-Logs-Url: https://github.com/microsoft/typespec/sessions/f4a12cd1-5ba2-4c12-bd25-9ca2677634c7 Co-authored-by: haiyuazhang <1924967+haiyuazhang@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Fix stale FQN storage in AddTypeToKeep method
[http-client-csharp] Lazily resolve TypeProvider FQN in AddTypeToKeep to prevent stale namespace after visitor changes
Apr 6, 2026
commit: |
Contributor
jorgerangel-msft
left a comment
There was a problem hiding this comment.
Can we please also run a regen preview?
| } | ||
|
|
||
| internal HashSet<string> AdditionalRootTypes { get; } = []; | ||
| private readonly HashSet<string> _additionalRootTypeNames = []; |
Contributor
There was a problem hiding this comment.
do we really need to create these additional hashsets? Is there possibly another way we can do this using just the original sets?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AddTypeToKeep(TypeProvider)eagerly snapshotstype.Type.FullyQualifiedNameat call time (during constructor), but visitors likeNamespaceVisitorrun later and change the namespace. The stored FQN becomes stale, soPostProcessor.ShouldKeepType()fails to match, silently internalizing models that have@@access(public).Changes
CodeModelGenerator.cs: StoreTypeProviderreferences inHashSet<TypeProvider>instead of eagerly resolving to strings.AdditionalRootTypes/NonRootTypesare now computed properties that resolve FQNs lazily at access time (post-visitors). TheAddTypeToKeep(string)overload is unchanged.ModelProviderTests.cs: AddedPublicModelTypeToKeepUpdatesAfterNamespaceChange— simulates a visitor namespace change and assertsAdditionalRootTypescontains the post-visitor FQN.