Conversation
| if( semanticModel.GetTypeInfo( assignmentSyntax.Right ).Type is INamedTypeSymbol assignedType | ||
| && assignedType.IsTupleType | ||
| ) { |
There was a problem hiding this comment.
Handle Value Tuples.
GetDeconstructionInfo does return stuff for them, but they don't have a Method, just some nested deconstructioninfos with Identity conversions - so need to extract the type info separately anyway.
| return AssignmentInfo.Create( | ||
| isInitializer: false, | ||
| expression: assignmentSyntax.Right, | ||
| assignedType: null |
There was a problem hiding this comment.
assignedType: null
This is an "error / unknown assignment" - there's probably a better way to signal this...
| DeconstructionInfo deconstruction = semanticModel.GetDeconstructionInfo( assignmentSyntax ); | ||
| if( deconstruction.Method == null ) { | ||
| return AssignmentInfo.Create( | ||
| isInitializer: false, | ||
| expression: assignmentSyntax.Right, | ||
| assignedType: null | ||
| ); | ||
| } | ||
|
|
||
| if( deconstruction.Method.Parameters.Length != lhsExpressions.Length ) { | ||
| return AssignmentInfo.Create( | ||
| isInitializer: false, | ||
| expression: assignmentSyntax.Right, | ||
| assignedType: null | ||
| ); | ||
| } | ||
|
|
||
| return AssignmentInfo.Create( | ||
| isInitializer: false, | ||
| expression: assignmentSyntax.Right, | ||
| assignedType: deconstruction.Method.Parameters[ i ].Type | ||
| ); |
There was a problem hiding this comment.
Only handles simple deconstructions, not nested ones like so:
class A {
public void Deconstruct( out string X, out B foo );
}
class B {
public void Deconstruct( out string Y, out string Z );
}
public void Foo() {
var (x, y, z) = new A();
}| ); | ||
| } | ||
|
|
||
| if( deconstruction.Method.Parameters.Length != lhsExpressions.Length ) { |
There was a problem hiding this comment.
Don't believe this can happen, just a sanity check.
There was a problem hiding this comment.
Actually I lied there, this is what's filtering out nested deconstruction.
I don't think it would be terribly hard to support, I just don't care to write the code.
| diagnostic = Diagnostic.Create( | ||
| Diagnostics.NonImmutableTypeHeldByImmutable, | ||
| assignment.Expression.GetLocation(), | ||
| "blarg", "blarg", "blarg" | ||
| ); | ||
| return AssignmentQueryKind.Hopeless; |
There was a problem hiding this comment.
Need to add some sort of new "Unexpected" diagnostic. (We currently have UnexpectedTypeKind and UnexpectedMemberKind)
| ); | ||
| } | ||
|
|
||
| public static AssignmentInfo Create( |
There was a problem hiding this comment.
Could the constructor just be public?
There was a problem hiding this comment.
Yeah for sho. Discovering the end solution organically.
WIP - opening up to chat