-
Notifications
You must be signed in to change notification settings - Fork 4k
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix issue with 'use explicit cast' and compound assignments #74225
Conversation
SemanticModel semanticModel, ExpressionSyntax targetNode, ITypeSymbol conversionType) | ||
{ | ||
// The compiler is very ambiguous with assignment expressions `(a += b)`. An error on it may be an error on the | ||
// entire expression or on the RHS of the assignment. Have to reverse engineer what it is doing here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this is the main fix.
/// </summary> | ||
private const int MaximumConversionOptions = 3; | ||
|
||
protected abstract TExpressionSyntax Cast(TExpressionSyntax expression, ITypeSymbol type); | ||
protected abstract void GetPartsOfCastOrConversionExpression(TExpressionSyntax expression, out SyntaxNode type, out SyntaxNode castedExpression); | ||
protected abstract void GetPartsOfCastOrConversionExpression(TExpressionSyntax expression, out SyntaxNode type, out TExpressionSyntax castedExpression); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
stronger type.
using var _ = ArrayBuilder<(TExpressionSyntax node, ITypeSymbol type)>.GetInstance(out var candidates); | ||
|
||
this.AddPotentialTargetTypes(document, semanticModel, root, diagnosticId, spanNode, candidates, cancellationToken); | ||
candidates.RemoveDuplicates(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sharing common code between C# and VB
@akhera99 ptal :) |
this.Cast((TExpressionSyntax)castedExpression, conversionType) | ||
.WithTriviaFrom(targetNode) | ||
.WithAdditionalAnnotations(Simplifier.Annotation)); | ||
var firstConversion = semanticFacts.ClassifyConversion(semanticModel, castedExpression, castType); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: could move the def of semanticFacts to here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yup. though i'm ok with this.
Fixes #56141.