Skip to content

Bug with goto case (n{u}int)myconstant when a prior case myconstant: exists before it #81784

@hamarb123

Description

@hamarb123

Version Used: lab.razor.fyi, sharplab.io, godbolt.org

Steps to Reproduce:

using System;

switch ((object)(nint)2)
{
    case 2:
        break;
    case (nint)2:
        Console.WriteLine("Case 2");
        goto case (nint)2;
}

Link

Expected Behavior:

Loops printing "Case 2" forever.

Actual Behavior:

Prints "Case 2" only once.

Note: the following code blocks do not exhibit the bug:

using System;

switch ((object)(nuint)2)
{
    case 2:
        break;
    case (nuint)2:
        Console.WriteLine("Case 2");
        goto case (nuint)2;
}
using System;

switch ((object)(long)2)
{
    case 2:
        break;
    case (long)2:
        Console.WriteLine("Case 2");
        goto case (long)2;
}
using System;

switch ((object)(int)2)
{
    case (short)2:
        break;
    case 2:
        Console.WriteLine("Case 2");
        goto case (int)2;
}
using System;

switch ((object)2L)
{
    case (nint)2:
        break;
    case 2L:
        Console.WriteLine("Case 2");
        goto case 2L;
}
using System;

switch ((object)(nint)2)
{
    case (nint)2:
        Console.WriteLine("Case 2");
        goto case (nint)2;
}

This case also exhibits it:

using System;

switch ((object)(nuint)2)
{
    case (uint)2u:
        break;
    case (nuint)2:
        Console.WriteLine("Case 2");
        goto case (nuint)2;
}

Metadata

Metadata

Assignees

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions