Skip to content
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

Improve error for casting negative value to enum #32057

Open
hughbe opened this issue Dec 29, 2018 · 1 comment
Open

Improve error for casting negative value to enum #32057

hughbe opened this issue Dec 29, 2018 · 1 comment
Labels
Area-Compilers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings.
Milestone

Comments

@hughbe
Copy link

hughbe commented Dec 29, 2018

Example:

using System;

public class Program
{
    public void T()
    {
        var value = (ConsoleColor)-1;
    }
}

We get two error messages:

Example.cs(7,22): error CS0119: 'ConsoleColor' is a type, which is not valid in the given context
Example.cs(7,21): error CS0075: To cast a negative value, you must enclose the value in parentheses.

Can we get rid of the first error if the second is present? It's fairly obvious what we're trying to do and I often get this error as I forgot to add the parens

@Neme12
Copy link
Contributor

Neme12 commented Dec 29, 2018

This looks like a candidate for a code fix

@jaredpar jaredpar added the Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings. label Jan 2, 2019
@jaredpar jaredpar added this to the Backlog milestone Jan 2, 2019
@gafter gafter added the Bug label Sep 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compilers Bug Concept-Diagnostic Clarity The issues deals with the ease of understanding of errors and warnings.
Projects
None yet
Development

No branches or pull requests

4 participants