Skip to content

Commit 0ed8391

Browse files
committed
recognize types and arrays in F# attribute contructor arguments
1 parent 192beb8 commit 0ed8391

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

src/fsharp/infos.fs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2541,7 +2541,7 @@ let rec evalILAttribElem e =
25412541
| ILAttribElem.TypeRef (Some _t) -> fail()
25422542
| ILAttribElem.TypeRef None -> null
25432543

2544-
let evalFSharpAttribArg e =
2544+
let rec evalFSharpAttribArg g e =
25452545
match e with
25462546
| Expr.Const(c,_,_) ->
25472547
match c with
@@ -2560,8 +2560,9 @@ let evalFSharpAttribArg e =
25602560
| Const.Zero -> null
25612561
| Const.String s -> box s
25622562
| _ -> fail()
2563-
// TODO: typeof<..> in attribute values
2564-
// TODO: arrays in attribute values
2563+
| Expr.Op (TOp.Array,_,a,_) -> box [| for i in a -> evalFSharpAttribArg g i |]
2564+
| TypeOfExpr g ty -> box ty
2565+
// TODO: | TypeDefOfExpr g ty
25652566
| _ -> fail()
25662567

25672568
type AttribInfo =
@@ -2590,7 +2591,7 @@ type AttribInfo =
25902591
unnamedArgs
25912592
|> List.map (fun (AttribExpr(origExpr,evaluatedExpr)) ->
25922593
let ty = tyOfExpr g origExpr
2593-
let obj = evalFSharpAttribArg evaluatedExpr
2594+
let obj = evalFSharpAttribArg g evaluatedExpr
25942595
ty,obj)
25952596
| ILAttribInfo (g, amap, scoref, cattr, m) ->
25962597
let parms, _args = decodeILAttribData g.ilg cattr (Some scoref)
@@ -2605,7 +2606,7 @@ type AttribInfo =
26052606
namedArgs
26062607
|> List.map (fun (AttribNamedArg(nm,_,isField,AttribExpr(origExpr,evaluatedExpr))) ->
26072608
let ty = tyOfExpr g origExpr
2608-
let obj = evalFSharpAttribArg evaluatedExpr
2609+
let obj = evalFSharpAttribArg g evaluatedExpr
26092610
ty, nm, isField, obj)
26102611
| ILAttribInfo (g, amap, scoref, cattr, m) ->
26112612
let _parms, namedArgs = decodeILAttribData g.ilg cattr (Some scoref)

src/fsharp/vs/Symbols.fs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1711,19 +1711,25 @@ and FSharpType(cenv, typ:TType) =
17111711

17121712
and FSharpAttribute(cenv: cenv, attrib: AttribInfo) =
17131713

1714+
let rec resolveArgObj (arg: obj) =
1715+
match arg with
1716+
| :? TType as t -> box (FSharpType(cenv, t))
1717+
| :? (obj[]) as a -> a |> Array.map resolveArgObj |> box
1718+
| _ -> arg
1719+
17141720
member __.AttributeType =
17151721
FSharpEntity(cenv, attrib.TyconRef)
17161722

17171723
member __.IsUnresolved = entityIsUnresolved(attrib.TyconRef)
17181724

17191725
member __.ConstructorArguments =
17201726
attrib.ConstructorArguments
1721-
|> List.map (fun (ty, obj) -> FSharpType(cenv, ty), obj)
1727+
|> List.map (fun (ty, obj) -> FSharpType(cenv, ty), resolveArgObj obj)
17221728
|> makeReadOnlyCollection
17231729

17241730
member __.NamedArguments =
17251731
attrib.NamedArguments
1726-
|> List.map (fun (ty, nm, isField, obj) -> FSharpType(cenv, ty), nm, isField, obj)
1732+
|> List.map (fun (ty, nm, isField, obj) -> FSharpType(cenv, ty), nm, isField, resolveArgObj obj)
17271733
|> makeReadOnlyCollection
17281734

17291735
member __.Format(denv: FSharpDisplayContext) =

0 commit comments

Comments
 (0)