Decompiler translate "nullref" in IL into "null" in C#

4 posts, 0 answers
  1. Ruan
    Ruan avatar
    2 posts
    Member since:
    Aug 2014

    Posted 11 Sep Link to this post

    For example, IL code snippet here

    .class interface public auto ansi abstract IDemo
    {
        .method public hidebysig newslot abstract virtual instance class ReturnType Parse (
                string text,
                [opt] valuetype [NamespaceA]TypeA args,
                [opt] string options
            ) cil managed
        {
            .param [2] = nullref
            .param [3] = nullref
        }
    }

     

    In JustDecompile, it was translated to

    public interface IDemo
    {
        ReturnType Parse(string text, TypeA args = null, string options = null);
    }

     

    However, some type can not be convert from null, like the error message here:

    error CS1750: A value of type '<null>' cannot be used as a default parameter because there are no standard conversions to type 'TypeA'

     

    The correct code should be "ReturnType Parse(string text, TypeA args = default(TypeA), string options = default(string));"

  2. Alexander
    Admin
    Alexander avatar
    188 posts

    Posted 13 Sep Link to this post

    Hello,

    Can you provide us with sample code that compiled produce assembly with this IL?

    Regards,
    Alexander
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. Ruan
    Ruan avatar
    2 posts
    Member since:
    Aug 2014

    Posted 13 Sep Link to this post

    Yes.

    namespace Demo
    {
        public class Program
        {
            public static void Main(string[] args)
            {
                PrintPosition();
                System.Console.ReadLine();
            }
            public static void PrintPosition(Position pos = default(Position))
            {
                System.Console.WriteLine(pos.X + ", " + pos.Y);
            }
        }
        public struct Position
        {
            public int X;
            public int Y;
        }
    }

    This can be compiled and run(using default(type)), but decompiled code were turned into null.

     

  4. Alexander
    Admin
    Alexander avatar
    188 posts

    Posted 19 Sep Link to this post

    Hello,

    Thank you for the follow-up.

    The bug is now added to our backlog and will be fixed after prioritizing it.

    Your help is very appreciated and in order to express our gratitude we rewarded you with some Telerik points. Enjoy :)

    Regards,
    Alexander
    Progress Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top