Skip to content

Should we allow to disable reflection on a specific type? #4241

@MangelMaxime

Description

@MangelMaxime

With the code below,

type SubType<'T> =
    {
        SubValue: 'T
    }

[<Erase>]
type TypeA<'T> = TypeA of (unit -> SubType<'T>)

type Updates =
    {
        Func : TypeA<unit>
    }

Fable generates this error:

error FABLE: Cannot get type info of generic parameter T. Fable erases generics at runtime, try inlining the functions so generics can be resolved at compile time.

This is because, here Func : TypeA<unit> has a concrete type giving.

However, for a library I am working on I kind of need this type of code supported.

A workaround, is to enable --noReflection flag in Fable but it means not reflection can happen anywhere, so perhaps it could be nice to introduce a [<NoReflection>] attribute to disable it only for specific types.

Another workaround is to use an anonymous record:

type Updates =
    {|
        VarView : TypeA<unit>
    |}

I will see if I can rewrite my library to use the anonymous record, as it would be better to not introduce an attribute for a really specific usage.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions