Skip to content

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

Closed

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

Activity

  1. added
    Impact-Low
    on Aug 11, 2021
  2. added
    Area-Compiler-CodeGen
    on Sep 21, 2022
  3. added this to the Backlog milestone on Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area-Compiler-CodeGenImpact-Low

    Type

    No type

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions