Assert the shape of bound tree created fo user defined conversions#81896
Assert the shape of bound tree created fo user defined conversions#81896AlekseyTs merged 2 commits intodotnet:mainfrom
Conversation
| Conversion is represented by a single BoundConversion. | ||
| --> | ||
| <Field Name="ConversionGroupOpt" Type="ConversionGroup?"/> | ||
| <Field Name="InConversionGroupFlags" Type="InConversionGroupFlags"/> |
There was a problem hiding this comment.
nit: Is there a way we could avoid storing this in RELEASE build (if we only read it for assertions)? #Resolved
There was a problem hiding this comment.
nit: Is there a way we could avoid storing this in RELEASE build (if we only read it for assertions)?
I am planning to use this information in "production" code in upcoming changes
| /// <summary> | ||
| /// Flags assigned to individual conversion nodes associated with | ||
| /// the same <see cref="ConversionGroup"/> instance. | ||
| /// </summary> |
There was a problem hiding this comment.
Consider mentioning this is only meant to drive some assertions #Resolved
There was a problem hiding this comment.
Consider mentioning this is only meant to drive some assertions
That is not the intent long term
| ExceptionUtilities.UnexpectedValue(InConversionGroupFlags); | ||
| } | ||
| } | ||
| } |
There was a problem hiding this comment.
Is the goal to shrink usage of InConversionGroupFlags.Unspecified over time? Consider an assertion covering the remaining unspecified cases, hopefully that triggers when new conversion kinds are added. #Resolved
There was a problem hiding this comment.
Is the goal to shrink usage of
InConversionGroupFlags.Unspecifiedover time?
No, there is no such goal.
| // Need to represent the implicit conversion as a node in order to be able to produce correct diagnostics. | ||
| left = new BoundConversion(left.Syntax, left, conversion, node.Operator.Kind.IsChecked(), | ||
| explicitCastInCode: false, conversionGroupOpt: null, constantValueOpt: null, type: node.Operator.LeftType); | ||
| left = node.LeftConversion; |
There was a problem hiding this comment.
Is the above comment still applicable? #Resolved
There was a problem hiding this comment.
Is the above comment still applicable?
I think it is.
| new BoundConversion(boundRHS.Syntax, boundRHS, Conversion.Deconstruction, @checked: false, explicitCastInCode: false, conversionGroupOpt: null, | ||
| constantValueOpt: null, type: type, hasErrors: true), | ||
| new BoundConversion(boundRHS.Syntax, boundRHS, Conversion.Deconstruction, @checked: false, explicitCastInCode: false, | ||
| conversionGroupOpt: null, inConversionGroupFlags: InConversionGroupFlags.Unspecified, constantValueOpt: null, type: type, hasErrors: true), |
There was a problem hiding this comment.
I'd probably not specify parameter name for InConversionGroupFlags arguments, unless required
Done
| public bool Equals(Conversion other) | ||
| { | ||
| return this.Kind == other.Kind && this.Method == other.Method; | ||
| return this.Kind == other.Kind && Equals(this._uncommonData, other._uncommonData); |
There was a problem hiding this comment.
nit: just curious, how did you spot this? #Resolved
There was a problem hiding this comment.
how did you spot this?
Some logic that I was adding to Validate wasn't quite working because of false positives from comparison operators. I think that logic was changed, but the problem got noticed.
|
@dotnet/roslyn-compiler For a second review |
| [Flags] | ||
| internal enum InConversionGroupFlags : ushort | ||
| { | ||
| Unspecified = 0, |
There was a problem hiding this comment.
Does 'unspecified' reflect in a point in time where we're just choosing to not provide more specific data? or is it a strong value that we woudl expect to stay the same in all the locations were currently passing it in.
My guess is the former, but it's not readily apparent to me. #Resolved
There was a problem hiding this comment.
Put another way, will we likkely update some of the places that currently pass 'unspecified' to pass something more specific when we realize there are useful conversion checks we want?
There was a problem hiding this comment.
Put another way, will we likkely update some of the places that currently pass 'unspecified' to pass something more specific when we realize there are useful conversion checks we want?
I think making a change like that in the future would be fine.
| @checked: conversion.Checked, | ||
| explicitCastInCode: conversion.ExplicitCastInCode, | ||
| conversionGroupOpt: null, | ||
| conversionGroupOpt: null, inConversionGroupFlags: InConversionGroupFlags.TupleBinaryOperatorPendingLowering, |
There was a problem hiding this comment.
could you wrap this to keep each arg on its own line like before? tnx. #Resolved
There was a problem hiding this comment.
could you wrap this to keep each arg on its own line like before?
Done
| // Need to represent the implicit conversion as a node in order to be able to produce correct diagnostics. | ||
| left = new BoundConversion(left.Syntax, left, conversion, node.Operator.Kind.IsChecked(), | ||
| explicitCastInCode: false, conversionGroupOpt: null, constantValueOpt: null, type: node.Operator.LeftType); | ||
| left = node.LeftConversion; |
There was a problem hiding this comment.
i'm curious why this was changed. can you provide more info on that? #Resolved
There was a problem hiding this comment.
i'm curious why this was changed. can you provide more info on that?
We already have the conversion node, no need to "re-invent" it
| Assert.Equal(expectedConversion, conversionOperation.GetConversion()); | ||
| Conversion conversion = conversionOperation.GetConversion(); | ||
| Assert.Equal(ConversionKind.CollectionExpression, conversion.Kind); | ||
| AssertEx.SequenceEqual(ImmutableArray.Create(Conversion.Boxing, Conversion.Boxing), conversion.UnderlyingConversions); |
There was a problem hiding this comment.
since SeqEqual is really just validating same values in same order, the above may be clearer as
| AssertEx.SequenceEqual(ImmutableArray.Create(Conversion.Boxing, Conversion.Boxing), conversion.UnderlyingConversions); | |
| AssertEx.SequenceEqual([Conversion.Boxing, Conversion.Boxing], conversion.UnderlyingConversions); |
as it's not really needed to specify the underlying temp collection type used to group the values. #Resolved
No description provided.