Skip to content

Commit

Permalink
Fix 316 - correctly handle null array values in attributes
Browse files Browse the repository at this point in the history
fixes #316
closes #433

commit 6d9584c
Author: Don Syme <[email protected]>
Date:   Sat May 9 18:14:42 2015 +0100

    fix 316

commit da56716
Author: Don Syme <[email protected]>
Date:   Sat May 9 17:45:54 2015 +0100

    Fix 316
  • Loading branch information
dsyme authored and latkin committed May 18, 2015
1 parent 92a064b commit cccf5b9
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
3 changes: 3 additions & 0 deletions src/absil/il.fs
Original file line number Diff line number Diff line change
Expand Up @@ -4388,6 +4388,8 @@ and encodeCustomAttrValue ilg ty c =
match ty, c with
| ILType.Boxed tspec, _ when tspec.Name = tname_Object ->
[| yield! encodeCustomAttrElemTypeForObject c; yield! encodeCustomAttrPrimValue ilg c |]
| ILType.Array (shape, _), ILAttribElem.Null when shape = ILArrayShape.SingleDimensional ->
[| yield! i32AsBytes 0xFFFFFFFF |]
| ILType.Array (shape, elemType), ILAttribElem.Array (_,elems) when shape = ILArrayShape.SingleDimensional ->
[| yield! i32AsBytes elems.Length; for elem in elems do yield! encodeCustomAttrValue ilg elemType elem |]
| _ ->
Expand Down Expand Up @@ -4755,6 +4757,7 @@ let decodeILAttribData ilg (ca: ILAttribute) scope =
parseVal ty sigptr
| ILType.Array(shape,elemTy) when shape = ILArrayShape.SingleDimensional ->
let n,sigptr = sigptr_get_i32 bytes sigptr
if n = 0xFFFFFFFF then ILAttribElem.Null,sigptr else
let rec parseElems acc n sigptr =
if n = 0 then List.rev acc else
let v,sigptr = parseVal elemTy sigptr
Expand Down
6 changes: 5 additions & 1 deletion src/fsharp/ilxgen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5682,7 +5682,11 @@ and GenAttribArg amap g eenv x (ilArgTy:ILType) =

match x,ilArgTy with

(* Detect standard constants *)
// Detect 'null' used for an array argument
| Expr.Const(Const.Zero,_,_),ILType.Array _ ->
ILAttribElem.Null

// Detect standard constants
| Expr.Const(c,m,_),_ ->
let tynm = ilArgTy.TypeSpec.Name
let isobj = (tynm = "System.Object")
Expand Down
22 changes: 22 additions & 0 deletions tests/fsharp/core/attributes/test.fsx
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,28 @@ module AttributeTestsOnExtensionProperties =
check "vwlnwer-0wreknj4" (test3()) "Equals: [||], GetHashCode: [||], GetType: [||], Object.get_ExtensionMethod: [|Inline|], Object.get_Item: [|Inline|], Object.set_Item: [|Inline|], ToString: [||]"


module ParamArrayNullAttribute =
open System

type Attr([<ParamArray>] pms: obj[]) =
inherit Attribute()
override x.ToString() = sprintf "Attr(%A)" pms

[<Attr(null)>]
let f () = ()

let test3() =
match <@ f() @> with
| Quotations.Patterns.Call(_, m, _) ->
m.GetCustomAttributes(typeof<Attr>, false)
|> Seq.map (fun x -> x.ToString())
|> String.concat ", "
| _ -> failwith "unreachable 3"

check "vwcewecioj9" (test3()) "Attr(<null>)"



(*-------------------------------------------------------------------------
!* Test passed?
*------------------------------------------------------------------------- *)
Expand Down

0 comments on commit cccf5b9

Please sign in to comment.