提交 92d02e11 编写于 作者: P Patrick Widauer

Basic implementation of CS0075. (Issue #13585)

上级 00116264
......@@ -435,6 +435,14 @@ private BoundExpression BindSimpleBinaryOperator(BinaryExpressionSyntax node, Di
if (left.HasAnyErrors || right.HasAnyErrors)
{
if (node.OperatorToken.Kind() == SyntaxKind.MinusToken
&& !right.HasAnyErrors
&& left.Kind == BoundKind.BadExpression
&& left.Type.Kind == SymbolKind.NamedType)
{
Error(diagnostics, ErrorCode.ERR_PossibleBadNegCast, node);
}
// NOTE: no user-defined conversion candidates
return new BoundBinaryOperator(node, kind, left, right, ConstantValue.NotAvailable, null, LookupResultKind.Empty, GetBinaryOperatorErrorType(kind, diagnostics, node), true);
}
......
......@@ -7459,6 +7459,15 @@ internal class CSharpResources {
}
}
/// <summary>
/// Looks up a localized string similar to To cast a negative value, you must enclose the value in parentheses..
/// </summary>
internal static string ERR_PossibleBadNegCast {
get {
return ResourceManager.GetString("ERR_PossibleBadNegCast", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Cannot define/undefine preprocessor symbols after first token in file.
/// </summary>
......
......@@ -4975,4 +4975,7 @@ To remove the warning, you can use /reference instead (set the Embed Interop Typ
<data name="ERR_ThrowMisplaced" xml:space="preserve">
<value>A throw expression is not allowed in this context.</value>
</data>
<data name="ERR_PossibleBadNegCast" xml:space="preserve">
<value>To cast a negative value, you must enclose the value in parentheses.</value>
</data>
</root>
\ No newline at end of file
......@@ -70,7 +70,7 @@ internal enum ErrorCode
ERR_CantOverrideNonEvent = 72,
ERR_AddRemoveMustHaveBody = 73,
ERR_AbstractEventInitializer = 74,
//ERR_PossibleBadNegCast = 75, Not used in Roslyn. Occurs so infrequently, not worth reimplementing.
ERR_PossibleBadNegCast = 75,
ERR_ReservedEnumerator = 76,
ERR_AsMustHaveReferenceType = 77,
WRN_LowercaseEllSuffix = 78,
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册