- Notifications
You must be signed in to change notification settings - Fork8.1k
FixTypeName.GetReflectionType() to work when theTypeName instance represents a generic type definition within aGenericTypeName#24985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Merged
Uh oh!
There was an error while loading.Please reload this page.
Merged
Changes from2 commits
Commits
Show all changes
6 commits Select commitHold shift + click to select a range
fca8dfe Set the cached type for `GenericTypeName.TypeName` as needed when the…
daxian-dbwfd6009a Minor update on test name
daxian-dbw92cf722 Pass generic argument count to `TypeName` when constructing a `Generi…
daxian-dbwbf7f23a Add more comments
daxian-dbwf6a956c Minor update
daxian-dbwbe17041 Add a check to the new constructor
daxian-dbwFile filter
Filter by extension
Conversations
Failed to load comments.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Jump to file
Failed to load files.
Loading
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
20 changes: 20 additions & 0 deletionssrc/System.Management.Automation/engine/parser/SymbolResolver.cs
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -697,6 +697,26 @@ private bool VisitGenericTypeName(GenericTypeName genericTypeName) | ||
| if (foundType != null) | ||
| { | ||
| ((ISupportsTypeCaching)genericTypeName).CachedType = foundType; | ||
| // When the generic type is in cache, we won't go through the code path that resolves | ||
| // 'genericTypeName.TypeName', which represents the generic type definition. | ||
| // | ||
| // - We could get the type definition by 'genericTypeName.TypeName.GetReflectionType()' | ||
| // in some cases, for example, when the generic type is 'System.Tuple[string, string]', | ||
| // calling 'GetReflectionType()' returns the 'System.Tuple' type. | ||
| // | ||
| // - But in much more other cases, calling that method won't return the type definition, | ||
| // for example, when the generic type is 'System.Collections.Generic.List[string]', | ||
| // the call returns 'null' because 'System.Collections.Generic.List' is not a valid type. | ||
| // | ||
| // In the latter cases, given that we already have the generic type, we can get the type | ||
| // definition and assign it to the cached type of 'genericTypeName.TypeName'. | ||
| var genericDefinition = genericTypeName.TypeName; | ||
| if (genericDefinition.GetReflectionType() is null) | ||
| { | ||
| ((ISupportsTypeCaching)genericDefinition).CachedType = foundType.GetGenericTypeDefinition(); | ||
daxian-dbw marked this conversation as resolved. OutdatedShow resolvedHide resolvedUh oh!There was an error while loading.Please reload this page. | ||
| } | ||
| return true; | ||
| } | ||
25 changes: 25 additions & 0 deletionstest/powershell/Language/Parser/Parsing.Tests.ps1
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
Oops, something went wrong.
Uh oh!
There was an error while loading.Please reload this page.
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.