Support declaration and consumption of user-defined Unsigned Right Shift operator.#60616
Conversation
1 similar comment
|
Looking |
| throw null; | ||
| } | ||
|
|
||
| public static int operator >>(C4 x, int y) |
There was a problem hiding this comment.
Consider adding a positive case for parameters being nullable: public static int operator >>>(S1? x, int? y) #Closed
| result &= CheckFeatureAvailability(node, MessageID.IDS_FeatureCheckedUserDefinedOperators, diagnostics); | ||
| Debug.Assert((methodOpt.Name == WellKnownMemberNames.UnsignedRightShiftOperatorName) == isUnsignedRightShift); | ||
|
|
||
| if (Compilation.SourceModule != methodOpt.ContainingModule) |
There was a problem hiding this comment.
I didn't understand why the unsigned right shift operator LangVer check is conditioned on resolved method being in source. I would have expected an unconditional LangVer diagnostic for >>> where ever the best signature is found. #Closed
There was a problem hiding this comment.
I didn't understand why the unsigned right shift operator LangVer check is conditioned on resolved method being in source. I would have expected an unconditional LangVer diagnostic for
>>>where ever the best signature is found.
- This logic is not new
- If the operator is declared in the same module (note, not just in source), we perform the check on the declaration and report the error, if needed. Reporting the same error at every consumption site would only add more noise.
| operatorToken.ValueText + operatorToken2.ValueText + operatorToken3.ValueText, | ||
| operatorToken3.GetTrailingTrivia()); | ||
|
|
||
| operatorToken = CheckFeatureAvailability(operatorToken, MessageID.IDS_FeatureUnsignedRightShift, forceWarning: true); |
There was a problem hiding this comment.
nit: Why do a parser LangVer check as opposed to add check in Binder_Cref? #Closed
There was a problem hiding this comment.
Why do a parser LangVer check as opposed to add check in Binder_Cref?
Just following the established pattern.
There was a problem hiding this comment.
Note that these are warnings, not errors
|
|
||
| case WellKnownMemberNames.LeftShiftOperatorName: | ||
| case WellKnownMemberNames.RightShiftOperatorName: | ||
| case WellKnownMemberNames.UnsignedRightShiftOperatorName: |
There was a problem hiding this comment.
nit: consider updating comment in CheckShiftSignature (add >>>) #Closed
jcouv
left a comment
There was a problem hiding this comment.
Done with review pass (iteration 2)
|
@333fred, @dotnet/roslyn-compiler For the second review. |
| /// Returns false if reported an error, true otherwise. | ||
| /// </summary> | ||
| private bool CheckConstraintLanguageVersionAndRuntimeSupportForOperator(SyntaxNode node, MethodSymbol? methodOpt, TypeSymbol? constrainedToTypeOpt, BindingDiagnosticBag diagnostics) | ||
| private bool CheckConstraintLanguageVersionAndRuntimeSupportForOperator(SyntaxNode node, MethodSymbol? methodOpt, bool isUnsignedRightShift, TypeSymbol? constrainedToTypeOpt, BindingDiagnosticBag diagnostics) |
There was a problem hiding this comment.
Consider just passing the operator kind, and letting the "is unsigned right shift" logic be contained within this method, rather than needing to be specified by a caller. #WontFix
| // PROTOTYPE(UnsignedRightShift): This code was previously allowed. Confirm that we are Ok with this | ||
| // breaking change and document it. | ||
| compilation1.VerifyDiagnostics( | ||
| // (9,40): error CS0571: 'C1.operator >>>(C1, int)': cannot explicitly call operator or accessor |
There was a problem hiding this comment.
Would it be worth adding a version of this test without the specialname flag in the IL? #Pending
There was a problem hiding this comment.
Would it be worth adding a version of this test without the specialname flag in the IL?
A method like that can be defined in plain C#.
| } | ||
|
|
||
| static C1? Test1(C1? x, int? y) => x >>> y; | ||
| static C1? Test2(C1? x, int? y) => x >> y; |
There was a problem hiding this comment.
Unused?
I think it is used for IL comparison
| return x; | ||
| } | ||
|
|
||
| static C1? Test2(C1? x, int? y) |
There was a problem hiding this comment.
Unused?
Used for IL comparison
https://github.com/dotnet/csharplang/blob/main/proposals/unsigned-right-shift-operator.md
Also added language version checks.
Test plan #60433