@@ -121,7 +121,6 @@ type WriterState =
121121 onlerefs: Table < int * int []>
122122 osimpletys: Table < int >
123123 oglobals: TcGlobals
124- mutable isStructThisArgPos: bool
125124 ofile: string
126125/// Indicates if we are using in-memory format, where we store XML docs as well
127126 oInMem: bool
@@ -506,9 +505,13 @@ let p_maybe_lazy p (x: MaybeLazy<_>) st =
506505 p_ lazy_ impl p x.Value st
507506
508507let p_hole () =
509- let h = ref( None: 'Tpickler option)
508+ let h = ref( None: ( 'T-> WriterState -> unit ) option)
510509( fun f -> h:= Some f),( fun x st -> match ! hwith Some f-> f x st| None-> pfailwith st" p_hole: unfilled hole" )
511510
511+ let p_hole2 () =
512+ let h = ref( None: ( 'Arg-> 'T-> WriterState-> unit) option)
513+ ( fun f -> h:= Some f),( fun arg x st -> match ! hwith Some f-> f arg x st| None-> pfailwith st" p_hole2: unfilled hole" )
514+
512515let u_array_core f n st =
513516let res = Array.zeroCreate n
514517for i= 0 to n-1 do
@@ -710,8 +713,7 @@ let pickleObjWithDanglingCcus inMem file g scope p x =
710713 osimpletys= Table<_>. Create" osimpletys"
711714 oglobals= g
712715 ofile= file
713- oInMem= inMem
714- isStructThisArgPos= false }
716+ oInMem= inMem}
715717 p x st1
716718let sizes =
717719 st1.otycons.Size,
@@ -733,8 +735,7 @@ let pickleObjWithDanglingCcus inMem file g scope p x =
733735 osimpletys= Table<_>. Create" osimpletys (fake)"
734736 oglobals= g
735737 ofile= file
736- oInMem= inMem
737- isStructThisArgPos= false }
738+ oInMem= inMem}
738739 p_ tup7
739740( p_ array p_ encoded_ ccuref)
740741( p_ tup3 p_ int p_ int p_ int)
@@ -1266,7 +1267,9 @@ let u_rfref st = let a,b = u_tup2 u_tcref u_string st in RFRef(a,b)
12661267let u_tpref st = u_ local_ item_ ref st.itypars st
12671268
12681269// forward reference
1269- let fill_p_ty , p_ty = p_ hole()
1270+ let fill_p_ty2 , p_ty2 = p_ hole2()
1271+
1272+ let p_ty = p_ ty2false
12701273let p_tys = ( p_ list p_ ty)
12711274
12721275let fill_p_attribs , p_attribs = p_ hole()
@@ -1291,9 +1294,7 @@ let p_nonlocal_val_ref (nlv:NonLocalValOrMemberRef) st =
12911294match key.TypeForLinkagewith
12921295| None-> false
12931296| Some ty-> checkForInRefStructThisArg st ty
1294- st.isStructThisArgPos<- isStructThisArgPos
1295- p_ option p_ ty key.TypeForLinkage st
1296- st.isStructThisArgPos<- false
1297+ p_ option( p_ ty2 isStructThisArgPos) key.TypeForLinkage st
12971298
12981299let rec p_vref ctxt x st =
12991300match xwith
@@ -1553,9 +1554,17 @@ let u_tyar_spec st =
15531554
15541555let u_tyar_specs = ( u_ list u_ tyar_ spec)
15551556
1556- let _ = fill _ p _ ty ( fun ty st ->
1557+ let _ = fill _ p _ ty2 ( fun isStructThisArgPos ty st->
15571558let ty = stripTyparEqns ty
1558- let ty = if isInByrefTy st.oglobals ty&& st.isStructThisArgPosthen destByrefTy st.oglobals tyelse ty
1559+
1560+ // See comment on 'checkForInRefStructThisArg'
1561+ let ty =
1562+ if isInByrefTy st.oglobals ty&& isStructThisArgPosthen
1563+ // Convert the inref to a byref
1564+ mkByrefTy st.oglobals( destByrefTy st.oglobals ty)
1565+ else
1566+ ty
1567+
15591568match tywith
15601569| TType_ tuple( tupInfo, l) ->
15611570if evalTupInfoIsStruct tupInfothen
@@ -1566,11 +1575,15 @@ let _ = fill_p_ty (fun ty st ->
15661575| TType_ app( tc, tinst) -> p_ byte2 st; p_ tup2( p_ tcref" typ" ) p_ tys( tc, tinst) st
15671576| TType_ fun( d, r) ->
15681577 p_ byte3 st
1569- p _ ty d st
1570- st. isStructThisArgPos<- false
1578+ // Note, the "this" argument may be found in the domain position of a function type, so propagate the isStructThisArgPos value
1579+ p _ ty2 isStructThisArgPosd st
15711580 p_ ty r st
15721581| TType_ var r-> p_ byte4 st; p_ tpref r st
1573- | TType_ forall( tps, r) -> p_ byte5 st; p_ tup2 p_ tyar_ specs p_ ty( tps, r) st
1582+ | TType_ forall( tps, r) ->
1583+ p_ byte5 st
1584+ p_ tyar_ specs tps st
1585+ // Note, the "this" argument may be found in the body of a generic forall type, so propagate the isStructThisArgPos value
1586+ p_ ty2 isStructThisArgPos r st
15741587| TType_ measure unt-> p_ byte6 st; p_ measure_ expr unt st
15751588| TType_ ucase( uc, tinst) -> p_ byte7 st; p_ tup2 p_ ucref p_ tys( uc, tinst) st)
15761589
@@ -1838,9 +1851,7 @@ and p_ValData x st =
18381851 p_ ranges( x.ValReprInfo|> Option.map( fun _ -> x.val_ range, x.DefinitionRange)) st
18391852
18401853let isStructThisArgPos = x.IsMember&& checkForInRefStructThisArg st x.Type
1841- st.isStructThisArgPos<- isStructThisArgPos
1842- p_ ty x.val_ type st
1843- st.isStructThisArgPos<- false
1854+ p_ ty2 isStructThisArgPos x.val_ type st
18441855
18451856 p_ int64 x.val_ flags.PickledBits st
18461857 p_ option p_ member_ info x.MemberInfo st