-
Notifications
You must be signed in to change notification settings - Fork 864
Expand file tree
/
Copy pathEnumValueAsObjectArg01.fs
More file actions
38 lines (29 loc) · 1.24 KB
/
Copy pathEnumValueAsObjectArg01.fs
File metadata and controls
38 lines (29 loc) · 1.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// #Conformance #DeclarationElements #Attributes
// Regression test for https://github.com/dotnet/fsharp/issues/995
// An enum assigned to an attribute argument of type 'obj' must keep its enum type in the
// emitted metadata, instead of being stored as the underlying int32.
open System
type MyAttribute() =
inherit Attribute()
let mutable prop : obj = null
member _.Prop
with get () : obj = prop
and set (value: obj) = prop <- value
type MyEnum =
| A = 1
| B = 2
// An enum with a non-int32 underlying type, to exercise the encoded value width.
type LongEnum =
| P = 1L
| Q = 2L
[<My(Prop = MyEnum.B)>]
type MyClass = class end
[<My(Prop = LongEnum.Q)>]
type MyClassLong = class end
let propOf<'T> () = (typeof<'T>.GetCustomAttributes(false)[0] :?> MyAttribute).Prop
let intProp = propOf<MyClass> ()
if intProp.GetType() <> typeof<MyEnum> then failwith "MyEnum type was lost"
if Convert.ToString(intProp, Globalization.CultureInfo.InvariantCulture) <> "B" then failwith "expected \"B\""
let longProp = propOf<MyClassLong> ()
if longProp.GetType() <> typeof<LongEnum> then failwith "LongEnum type was lost"
if Convert.ToString(longProp, Globalization.CultureInfo.InvariantCulture) <> "Q" then failwith "expected \"Q\""