Skip to content

Interface stripping produces invalid outputs #1235

Closed
@MichalStrehovsky

Description

@MichalStrehovsky

Found this when I was looking at #1077 (it looks like having to declare IsAssignableFrom linker unsafe would be quite a pain.)

It wouldn't be completely academical to assume that an app that has some Foos implementing IFoo could end up in a situation where we have an empty array of Foos (because no Foo was allocated because the code that normally news them up was e.g. linked out) that we need to cast to an array of IFoo.

Linker currently produces invalid output for this because it strips the IFoo implementation off Foo:

using System;

interface IFoo { }

class Foo : IFoo { }

class Program
{
    static void Main()
    {
        // need to go through object to force a cast for added dramatic effect at runtime
        // otherwise this would just silently break type safety
        IFoo[] foos = (IFoo[])(object)new Foo[0];
    }
}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions