Hi all,

There are several bugs in Reflector. Below are code snippets that reproduce the bugs:
public struct ImplicitCastBug
{
    // Expected:
    // ((int)this).ToString();

    // Actual:
    // *(((int*) this)).ToString();
    public void TestMethod()
    {
        int i = this;
        i.ToString();
    }

    public static implicit operator int(ImplicitCastBug x)
    {
        return 0;
    }
}

This one generates code that compiles but is not equivalent to original:
public class MissedClosureInitializationBug
{
    // To reproduce set optimization level to .NET 2.0 or higher.

    // Expected:
    // <>c__DisplayClass1 CS$<>8__locals2;
    // CS$<>8__locals2.x = 1;
    // this.AnotherMethod(new Action(CS$<>8__locals2, (IntPtr) this.<TestMethod>b__0));

    // Actual:
    // <>c__DisplayClass1 CS$<>8__locals2;
    // this.AnotherMethod(new Action(CS$<>8__locals2, (IntPtr) this.<TestMethod>b__0));
    public void TestMethod()
    {
        int x = 1;
        AnotherMethod(() =>
                          {
                              x++;
                              Console.WriteLine(x);
                          });
    }

    public void AnotherMethod(Action action)
    {
        action();
    }
}

This one is also generates non-equivalent code:
public class TypeInferenceBug
{
    // To reproduce set optimization level to None.

    // Expected:
    //     bool b;
    //     int i;
    //     char c;
    //     bool CS$4$0000;
    //     b = false;
    //     i = 0;
    //     c = 'a';
    //     if ((((b != false) || (i == 0)) ? false : ((c == 'a') == false)) != false)
    //     {
    //         goto Label_001F;
    //     }
    // Label_001F:
    //     return;

    // Actual:
    //     bool b;
    //     int i;
    //     char c;
    //     bool CS$4$0000;
    //     b = 0;
    //     i = 0;
    //     c = 97;
    //     if ((((b != null) || (i == null)) ? 0 : ((c == 97) == 0)) != null)
    //     {
    //         goto Label_001F;
    //     }
    // Label_001F:
    //     return;
    public void TestMethod()
    {
        bool b = false;
        int i = 0;
        char c = 'a';
        if (b || i == 0 || c == 'a')
        {
        }
    }
}
public class FixedBug
{
    // To reproduce set optimization level to .NET 1.0 or higher.

    // Actual:
    //     int[] CS$0$0000;
    //     int[] arr = new int[0];
    //     if (((CS$0$0000 = (arr == null) ? null : arr) != null) && (CS$0$0000.Length != 0))
    //     {
    //         goto Label_001D; // Compile error.
    //     }
    //     fixed (int* p = null) // Compile error.
    //     {
    //         goto Label_0025;
    //     Label_001D:
    //         p = CS$0$0000;
    //     Label_0025:
    //         this.AnotherMethod(p);
    //     }
    public unsafe void TestMethod()
    {
        int[] arr = new int[0];
        fixed (int* p = arr == null ? null : arr)
        {
            AnotherMethod(p);
        }
    }

    public unsafe void AnotherMethod(int* p)
    {
    }
}
Romchick
0

Comments

2 comments

  • Clive Tong
    Thanks for reporting these. I've added them to the bug tracking system.
    Clive Tong
    0
  • Romchick
    One more bug:
    // Expected:
        // [DebuggerTypeProxy(typeof(NonGenericNestedClassBug<>.NestedClass))]
    
        // Actual:
        // [DebuggerTypeProxy(typeof(NestedClass<>))]
        [DebuggerTypeProxy(typeof(NonGenericNestedClassBug<>.NestedClass))]
        public class NonGenericNestedClassBug<T>
        {
            // Expected:
            // public NestedClass TestMethod()
            // {
            //     return new NestedClass();
            // }
    
            // Actual:
            // public NestedClass<T> TestMethod()
            // {
            //     return new NestedClass<T>();
            // }
            public NestedClass TestMethod()
            {
                return new NestedClass();
            }
    
            public class NestedClass
            {
            }
        }
    
    Romchick
    0

Add comment

Please sign in to leave a comment.