Repository navigation
[VS] FOREACH VAR: resolve the loop variable of generic collections and arrays - #2129
Merged
RobertvanderHulst merged 1 commit intoOct 27, 2026
Merged
Conversation
…d arrays - FindIdentifier: keep the declared type arguments when a local or parameter is resolved (List<Customer> no longer becomes List<T>) - ResolveImpliedCollection: element type of arrays instead of the array type; for generic .NET collections read the element type from IEnumerable<T> and substitute the type arguments (Dictionary -> KeyValuePair<TKey,TValue>) - RetrieveElement: resolve the type of a member adjusted by AdjustGenericMember, so pair:Value: completes the members of TValue Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
Member completion on the loop variable of
FOREACH VARshowed nothing when the collection is a generic local or parameter:Same for a
Customer[]array (it offered the members ofSystem.Array) and forDictionary<STRING, Customer>(pair:Value:showed nothing).Causes
FindIdentifierreplaced theTypeNameof a local/parameter with the resolved type's full name. For a .NET generic that isList<T>, soGenericArgsbecame["T"]and the element typeTcould not be found.ResolveImpliedCollectionreturned the array type forX[]instead of the element type.Dictionary<TKey,TValue>[TKey]returnsTValue, but the loop enumeratesKeyValuePair<TKey,TValue>.AdjustGenericMemberonly fixed theTypeNameof the cloned member (QuickInfo was right). Completion readsResolvedType, which was still resolved fromTValue.Changes (
XSharpLookup.csonly)WithTypeArguments,GetTypeArguments; type arguments are split at the top level and trimmed).IEnumerable<T>implementation in the metadata, with the collection's type arguments filled in. The indexer stays as the fallback.AdjustGenericMember, resolve theResolvedTypeof the adjusted member.Known limitation: the generic member adjustment still runs only at the end of a chain, so a deeper chain such as
pair:Value:Name:is not covered yet.Test
Checked manually in VS 2022 (experimental instance) with the old parser. Completion now lists the members of
Customerfor a localList<Customer>, a localCustomer[], a parameterList<Customer>andpair:Value:over aDictionary<STRING, Customer>.VAR x := Customer{}andFOR VAR n := 1 TO 3work as before.🤖 Generated with Claude Code