Skip to content

The unmanged generic constraint is not recognized by C# #11935

@teo-tsirpanis

Description

@teo-tsirpanis

Consider the following class declaration:

type C<'T when 'T: unmanaged> = class end

When decompiled, it results in the following C# class declaration:

[Serializable]
[CompilationMapping(SourceConstructFlags.ObjectType)]
public class C<T>
{
}

The unmanaged constraint has disappeared. 'T does not have any constraints at all.

Because the unmanaged constrained appeared first in F#, it looks like it is stored in an F#-specific way (the SignatureData I guess?).

This is how it sould be represented to be recognized by C# (and F# for backwards compatibility, some code omitted for brevity):

namespace System.Runtime.CompilerServices

// This is a compiler-generated attribute. It has two other attributes,
// CompilerGenerated and Embedded, the latter of which is also compiler-generated.
type internal IsUnmanagedAttribute() = inherit System.Attribute()

namespace MyLibrary

type C<[<IsUnmanaged>] 'T when 'T: struct, unmanaged> = class end

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CodeGenIlxGen, ilwrite and things at the backendImpact-Low(Internal MS Team use only) Describes an issue with limited impact on existing code.

    Type

    No type

    Projects

    Status

    Done

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions