Interfaces Subclassing - Weirdness and Crashes

Issue #275 resolved
Steamroller Studios created an issue

Rather than trying to explain this, I've boiled it down to the following code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Sirenix.OdinInspector;

// The following code compiles and odin does not crash. but when you clike on the '+'
// it list BarSubclass when it shouldn't, if you click on BarSubclass you get an error.
// If i try and add the constraints in it compiles, but Odin crashes whenever you click on the '+'
public class Test : SerializedMonoBehaviour
    public List<ITestInterface<FooSubclass>> foos = new List<ITestInterface<FooSubclass>>();

public interface ITestInterface<T> // where T : TestGeneric<T>

public abstract class TestGeneric<T> : ITestInterface<T> // where T : TestGeneric<T>

public class FooSubclass : TestGeneric<FooSubclass>

public class BarSubclass : TestGeneric<BarSubclass>

public class FooSerializableObject : SerializedScriptableObject, ITestInterface<FooSubclass>

Once compiled, you can add the "Test" component to an empty game object. you should see an empty list called "foos"

Problem #1

If you click on the '+' you will see that it shows a list of classes. It will include 'BarSubclass', it shouldn't. If you click on it you get an error in the console saying the casting was incorrect.

Problem #2

In the code, if you uncomment the Generic constraints, and go back into Unity and press the '+', you get an insta-crash.

I'm not sure if i'm doing something super funky here with the constraints, but it compiles, so it should be supported.

Comments (2)

  1. Tor Esa Vestergaard
    • changed status to open

    After some testing, I've replicated the first error you describe, and failed to replicate the crash, using Odin, and Unity 2017.1.2f1. I don't know if Unity has fixed that crash in the intervening patches. Regardless, the first issue is definitely resolved in, and there is a very high likelihood that the second one is resolved as well. I've sent you a release candidate build of patch - could you confirm whether or not the issue is resolved in that patch?

  2. Log in to comment