Skip to content
This repository has been archived by the owner on Nov 1, 2020. It is now read-only.

EEType validation should cover instantiation #5913

Open
MichalStrehovsky opened this issue Jun 8, 2018 · 1 comment
Open

EEType validation should cover instantiation #5913

MichalStrehovsky opened this issue Jun 8, 2018 · 1 comment
Milestone

Comments

@MichalStrehovsky
Copy link
Member

using System.Reflection.Emit;

#pragma warning disable 649

internal class Program
{
    class Foo
    {
        public ILGenerator ILG;
    }

    class Bar<T>
    {
    }

    private static void Main(string[] args)
    {
        new Bar<Foo>();
    }
}

This should generate a program that throws a TypeLoadException at runtime (because the facade assemblies for Reflection.Emit are bogus for AOT - dotnet/corefx#30127), but instead we crash the compiler because we find out Foo cannot be loaded too late in the process.

The obvious fix would be to add factory.NecessaryTypeSymbol(typeArg); around here to make sure we hit the problem when compiling the problematic method (at which point this is handled by the existing infrastructure), except the current design of CheckCanGenerateEEType can't deal with recursion (adding the check makes us run out of stack for things like char implementing IEquatable<char>). It will need a slight rearchitecturing of the validation part.

@MichalStrehovsky MichalStrehovsky added this to the Preview milestone Jun 8, 2018
@MichalStrehovsky
Copy link
Member Author

Maybe a better repro that doesn't depend on whatever we do with Ref.Emit.

using System.Runtime.InteropServices;

internal class Program
{
    [StructLayout(LayoutKind.Explicit, Size = 0x10000)]
    struct Big { }

    class Bar<T>
    {
    }

    private static void Main(string[] args)
    {
        new Bar<Big[]>();
    }
}

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant