Open sharwell opened 7 years ago
Regarding to #20596. I've found some strange code (at least at my point of view) in src\compilers\csharp\portable\binder\Binder_Operators.cs file:
var best = this.UnaryOperatorOverloadResolution(kind, operand, node, diagnostics, out resultKind, out originalUserDefinedOperators);
if (!best.HasValue)
{
ReportUnaryOperatorError(node, diagnostics, operatorText, operand, resultKind);
return new BoundUnaryOperator(
node,
kind,
operand,
ConstantValue.NotAvailable,
null,
resultKind,
originalUserDefinedOperators,
GetSpecialType(SpecialType.System_Object, diagnostics, node),
hasErrors: true);
}
Why SpecialType.System_Object
used and not ErrorType since expression is invalid?
💠It seems like ideally the symbol returned would be the type of the operand, meaning it behaves in IntelliSense like the operand even if the operand (or operator) doesn't resolve. In almost all cases the unary operators do not change the type of the argument.
Version Used: 15.3 Preview 3
As described in https://github.com/dotnet/roslyn/pull/20596#issuecomment-312662668,
ReplacementChangesSemantics
fails to detect certain semantic changes, leading to broken diagnostics and code fixes for some cases. @zaytsev-victor has identified a potential solution in https://github.com/dotnet/roslyn/pull/20596#issuecomment-312857730 which could fix several outstanding bugs in this area.