提交 cccf5b98 编写于 作者: D Don Syme 提交者: latkin

Fix 316 - correctly handle null array values in attributes

fixes #316
closes #433

commit 6d9584caf54e0655c8c67375bc622dc3e38c2c28
Author: Don Syme <donsyme@fastmail.fm>
Date:   Sat May 9 18:14:42 2015 +0100

    fix 316

commit da567164f7c5d79119c13f5f5c2373b0dedd77d3
Author: Don Syme <donsyme@fastmail.fm>
Date:   Sat May 9 17:45:54 2015 +0100

    Fix 316
上级 92a064b1
......@@ -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 |]
| _ ->
......@@ -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
......
......@@ -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")
......
......@@ -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?
*------------------------------------------------------------------------- *)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册