question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Error reported for explicit conversion from native integer to enum

See original GitHub issue

Explicit conversions should be allowed from native integers to enum values.

enum E { }

class Program
{
    static void Main()
    {
        nint i = 1;
        nuint u = 2;
        E e;
        e = (E)i;
        e = (E)u;
    }
}

Expected: No errors

Result:

(10,13): error CS0030: Cannot convert type 'nint' to 'E'
(11,13): error CS0030: Cannot convert type 'nuint' to 'E'

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
Youssef1313commented, Sep 25, 2020

Good to know!

Consider also the implicit enumeration conversion case:

enum E { }

class Program
{
    static void Main()
    {
        const nint x = 0;
        const int y = 0;
        E e;
        e = x; // unexpected compile error.
        e = y; // compiles as expected.
    }
}
0reactions
cstoncommented, Sep 25, 2020

Thanks @Youssef1313. I’m already working on a fix.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Implicit conversion from int to enum class in switch statement
Incidentally, simple assignment without explicit cast such as pid a = propId; gives error in each compiler. Which one got it right? c++...
Read more >
Type conversion: Enum data types and integer
The enumeration to integer conversion operator converts the given enum operand to a signed or unsigned integer data type. In practice, the conversion...
Read more >
How to Handle the Incompatible Types Error in Java
The incompatible types error most often occurs when manual or explicit conversion between types is required, but it can also happen by ...
Read more >
Enum Classes in C++ and Their Advantage over ...
Class enum doesn't allow implicit conversion to int, and also doesn't compare enumerators from different enumerations. To define enum class ...
Read more >
Enumeration (or enum) in C
A Computer Science portal for geeks. It contains well written, well thought and well explained computer science and programming articles, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found