Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combinding struct field with units of measure will result managed type instead of unmanaged type. FS0001: A generic construct requires that the type 'S2' is an unmanaged type #276

Closed
zpodlovics opened this issue Feb 26, 2015 · 0 comments
Labels

Comments

@zpodlovics
Copy link

Hi,

As far as I know units of measure implemented with type erasure so at this case there should be no difference between the S1 and S2 types at runtime.

[<Measure>]
type Version

[<NoComparison;NoEquality>]
[<Struct>]
type S1 =
  val i: int64
  val v: int64

[<NoComparison;NoEquality>]
[<Struct>]
type S2 =
  val i: int64
  val v: int64<Version>

The complete proof of concept example are available at:
https://gist.github.com/zpodlovics/848f3c13928dfe1b0d00

However when I try to use it using NativeInterop.NativePtr the compilation will result the following error:

error FS0001: A generic construct requires that the type 'S2' is an unmanaged type

After commenting out the source of error the following line

let (s2: S2) = readPtr ptr

the program compiles and the decompiled bytecode shows no significant (except the class names) difference between S1 and S2, type erasure works as expected.

System environment: x86_64, Ubuntu 14.04, Mono 3.12.0 (from source based on tpokorra repo), F# 3.1.1.31 (from source).

According to the documentation which is available at: https://msdn.microsoft.com/en-us/library/dd233203.aspx

"The provided type must be an unmanaged type. Unmanaged types are either certain primitive types (sbyte, byte, char, nativeint, unativeint, float32, float, int16, uint16, int32, uint32, int64, uint64, or decimal), enumeration types, nativeptr<_>, or a non-generic structure whose fields are all unmanaged types."

Probably some parser/lexer or typing error or maybe something else. Thanks for your help,
Zoltan

Update: this issue is moved from fsharp/fsharp#390

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

No branches or pull requests

2 participants