Bug 5156 - Generic interface methods cause AOT crash
Summary: Generic interface methods cause AOT crash
Alias: None
Product: iOS
Classification: Xamarin
Component: XI runtime ()
Version: 5.2
Hardware: PC Mac OS
: --- normal
Target Milestone: Untriaged
Assignee: Zoltan Varga
Depends on:
Reported: 2012-05-17 18:45 UTC by Aaron Bockover
Modified: 2012-06-01 08:24 UTC (History)
2 users (show)

Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.

Please create a new report on Developer Community or GitHub with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:

Description Aaron Bockover 2012-05-17 18:45:13 UTC
Just ran into another generic/AOT issue in MT. I feel like though this may be a little different than other virtual/generic/AOT issues.

Given an interface:

interface IGetter
    T Get<T>();

And an implementation:

class Getter : IGetter
    public T Get<T>() { return default(T); }

And some other class:

abstract class Session
    public abstract IGetter Getter { get; }

And an implementation thereof:

class IosSession : Session
    private IGetter getter = new Getter();
    public override IGetter Getter { get { return getter; } }

AOT will fail:

new IosSession().Getter.Get<ENUM_TYPE>();

However, if the interface is removed:

abstract class Session
    public abstract Getter Getter { get; }

And an implementation thereof:

class IosSession : Session
    private Getter getter = new Getter();
    public override Getter Getter { get { return getter; } }

Everything works.

I assume this is because the interface is essentially introducing virtual method dispatching and thus the crash "makes sense."

However I also feel like the compiler can determine that the only implementation of IGetter will be Getter throughout the lifetime of the program - the field IosSession.getter is assigned only once, and the override IosSession.Getter property will only return that field value.
Comment 1 Rolf Bjarne Kvinge [MSFT] 2012-06-01 07:19:32 UTC
Zoltan, this looks like one of the current AOT limitations, am I right?
Comment 2 Zoltan Varga 2012-06-01 07:39:22 UTC
Comment 3 Rolf Bjarne Kvinge [MSFT] 2012-06-01 08:24:38 UTC
Closing as WONTFIX then.