Unchecked.defaultof<'T> where T: struct doesn't work properly, it creates null instead of the struct type constructor.
Actually, we do have code to deal with this: https://github.com/fable-compiler/Fable/blob/b587cc9a961560d98c87b41be1566778a11388d1/src/Fable.Transforms/Replacements.fs#L1052-L1055
And a test: https://github.com/fable-compiler/Fable/blob/b587cc9a961560d98c87b41be1566778a11388d1/tests/Main/MiscTests.fs#L815-L817
Do you have a failing example?
@alfonsogarciacaro Something like this:
type TestType<'T when 'T: struct>() =
let x = Unchecked.defaultof<'T>
Ah, ok. That's going to be difficult because we're not passing the generic info at runtime so it's not possible to locate the constructor :/ It should work in inlined functions though.
Closing as unsupported.
Should we error/emit a warning when the generic has a struct constraint as currently the compilation succeeds but creates wrong code? (I think we'd have to add the constraints to the generic params in Fable AST for add, as currently they only hold the name).