Announcement

Collapse
No announcement yet.

[CLOSED] [#3242] Implicit operator bypassed for [ObjectLiteral] types

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

    [CLOSED] [#3242] Implicit operator bypassed for [ObjectLiteral] types

    If I have a class with an implicit operator that converts it into a string and then assign an instance of that class to a string variable then I expect the implicit operator to be called. For a class without [ObjectLiteral] this works but it does not for classes with [ObjectLiteral].

    To illustrate:

    public class Program
    {
        public static void Main()
        {
            string msg = new MyString("Hello, World!");
    
            Console.WriteLine(msg);
        }
    }
    
    [ObjectLiteral(ObjectCreateMode.Constructor)]
    public class MyString
    {
        public MyString(string value)
        {
            Value = value;
        }
    
        public string Value { get; }
    
        public static implicit operator string(MyString value)
        {
            return (value == null) ? null : value.Value;
        }
    }
    Available at https://deck.net/5b041fe9f93f052aa697e4fa055a3bae

    The expected output is

    Hello, World!
    but the actual output is

    {
    "Value": "Hello, World!"
    }
    If the [ObjectLiteral(ObjectCreateMode.Constructor) attribute is removed then it works as expected.

    For other methods (ie. methods other than operator methods) that exist on [ObjectLiteral] types, the methods are defined either as statics on the type or as instance methods on the prototype and I would have expected something similar to be done for operator methods.
    Last edited by geoffrey.mcgill; 2017-10-31 @ 01:02 PM.

    #2
    Issue #3242 has been created to track this defect. A pull-request has been submitted with the fix and goal is to include in the upcoming 16.5.0 release.

    Comment


      #3
      The fix is effectively merged and published in Bridge 16.5.0, thanks for the report!

      Comment

      Working...
      X