Announcement

Collapse
No announcement yet.

[CLOSED] [#306] [1.8] Failure to identify generic static method on derived class as call targeti

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

    [CLOSED] [#306] [1.8] Failure to identify generic static method on derived class as call targeti

    If I have a base class with a static "New" function that has a single generic type parameter and I have a static "New" function on a class that derives from this base class, but with no generic type parameter on it - when I rely on type inference to try to call the generic function from the derived class, the JavaScript tries to call the non-generic version defined on the derived class (rather than the generic version on the base).

    This is hard to explain in words, it's easier in an example!

    public class TestComponent : Component<TestComponent.Props>
    {
        public static string New(Props props) { return New<TestComponent>(props); }
    
        public class Props
        {
            public string Name;
        }
    }
        
    public abstract class Component<TProps>
    {
        public static string New<TComponent>(TProps props) where TComponent : Component<TProps>
        {
            return "Props Type: " + typeof(TProps);
        }
    }
    This compiles fine in Visual Studio (and would work with "real" C#), but the translated JavaScript fails at runtime when TestComponent.New is called with the error

    Uncaught TProps is not defined
    If I change it so that type inference is not relied on, so the "New" function in TestComponent is

    public static string New(Props props) { return Component<TestComponent.Props>.New<TestComponent>(props); }
    then it works as expected.

    The differences in the JavaScript are that when type inference is relied upon (in the first code sample), the following is generated -

    statics: {
        $new: function (props) {
            return Demo.Component$1(TProps).$new(BridgeExamples.TestComponent, BridgeExamples.TestComponent.Props)(props);
        }
    }
    but when the types are explicitly specified, this is generated instead -

    statics: {
        $new: function (props) {
            return Demo.Component$1(BridgeExamples.TestComponent.Props).$new(BridgeExamples.TestComponent, BridgeExamples.TestComponent.Props)(props);
    ‚Äč    }
    }
    I presume that this explains the "TProps" error - since in the first Javascript sample the "TProps" value is never set?

    #2
    Thanks for this report. We are investigating.

    Comment


      #3
      The issue is being tracked at GitHub #306

      Comment


        #4
        The issue is fixed.
        Commit 61cf189
        Last edited by Leonid; 2015-07-15 @ 02:11 PM.

        Comment

        Working...
        X