Add a prototype implementation for GetTypeInfo(PatternSyntax)#26521
Add a prototype implementation for GetTypeInfo(PatternSyntax)#26521gafter merged 3 commits intodotnet:features/recursive-patternsfrom
Conversation
This is a first draft of dotnet#26494, and requires more testing.
| <Field Name="DeconstructMethodOpt" Type="MethodSymbol" Null="allow"/> | ||
| <Field Name="Deconstruction" Type="ImmutableArray<BoundPattern>" Null="allow"/> | ||
| <Field Name="PropertiesOpt" Type="ImmutableArray<(Symbol symbol, BoundPattern pattern)>" Null="allow"/> | ||
| <Field Name="Deconstruction" Type="ImmutableArray<BoundSubpattern>" Null="allow"/> |
There was a problem hiding this comment.
Not related to this PR: should Deconstruction be called DeconstructionOpt? #Resolved
There was a problem hiding this comment.
We are inconsistent about that. I think we should do a sweep to some consistent state. #Resolved
| </Node> | ||
|
|
||
| <Node Name="BoundSubpattern" Base="BoundNode"> | ||
| <Field Name="Symbol" Type="Symbol" Null="allow"/> |
| TypeSymbol elementType = isError ? CreateErrorType() : elementTypes[i]; | ||
| BoundPattern boundSubpattern = BindVarDesignation(node, tupleDesignation.Variables[i], elementType, isError, diagnostics); | ||
| patterns.Add(boundSubpattern); | ||
| subPatterns.Add(new BoundSubpattern(node, null, boundSubpattern)); |
There was a problem hiding this comment.
Nit: name null here and below. #Resolved
| BoundNode highestBoundNode, | ||
| BoundNode boundNodeForSyntacticParent) | ||
| { | ||
| if (lowestBoundNode is BoundPattern pat) |
There was a problem hiding this comment.
Nit: pattern can be spelled out #Resolved
| Assert.Equal(ex.Type, typeInfo.Type.ToTestDisplayString()); | ||
| Assert.Equal(ex.ConvertedType, typeInfo.ConvertedType.ToTestDisplayString()); | ||
| } | ||
| Assert.Equal(expected.Length, i); |
There was a problem hiding this comment.
Could you add testing of GetTypeInfo to some existing types tests as well? #ByDesign
There was a problem hiding this comment.
Yes, but not this round. I'm keeping the bug for this new API open until testing is more complete.
In reply to: 185133922 [](ancestors = 185133922)
| /// <summary> | ||
| /// Helper class to remove alias qualifications. | ||
| /// </summary> | ||
| class RemoveAliasQual : CSharpSyntaxRewriter |
There was a problem hiding this comment.
Please consider spelling out Qualifiers. #Resolved
| foundField = CheckIsTupleElement(subPattern.NameColon.Name, (NamedTypeSymbol)declType, name, i, diagnostics); | ||
| // PROTOTYPE(patterns2): Should the tuple field binding for the name be stored somewhere in the node? | ||
|
|
||
| } |
There was a problem hiding this comment.
Unnecessary blank line. #Resolved
|
Please merge latest patterns changes into |
| var ex = expected[i++]; | ||
| Assert.Equal(ex.Source, pat.ToString()); | ||
| Assert.Equal(ex.Type, typeInfo.Type.ToTestDisplayString()); | ||
| Assert.Equal(ex.ConvertedType, typeInfo.ConvertedType.ToTestDisplayString()); |
There was a problem hiding this comment.
@gafter Another general discussion: could we reconsider factoring PropertyPatternSyntax (with a type, property sub-pattern and designation) and DeconstructionPatternSyntax (with the same plus parens and list of patterns)?
The parens and list of patterns are pulled into a deconstruction sub-pattern. Then we can have one node with optional type, optional positional sub-pattern and optional property sub-pattern.
I understand that you wanted to have the syntax nodes enforce some constraints (you can't be missing the type, positional and property sub-patterns).
But on the other hand, my experience dealing with the syntax API so far is that it would be easier to deal with and reason about.
There was a problem hiding this comment.
what about exposing their common properties through an abstract base class (Type, PropertySubpattern, Designation)?
This is a first draft of #26494, and requires more testing.