@@ -624,7 +624,7 @@ and CheckExpr (cenv:cenv) (env:env) expr (context:ByrefContext) =
624624 CheckExprsPermitByrefs cenv env rest
625625
626626| Expr.Op( c, tyargs, args, m) ->
627- CheckExprOp cenv env( c, tyargs, args, m) context
627+ CheckExprOp cenv env( c, tyargs, args, m) context expr
628628
629629// Allow 'typeof<System.Void>' calls as a special case, the only accepted use of System.Void!
630630| TypeOfExpr cenv.g tywhen isVoidTy cenv.g ty->
@@ -734,7 +734,7 @@ and CheckInterfaceImpls cenv env baseValOpt l =
734734and CheckInterfaceImpl cenv env baseValOpt ( _ty , overrides ) =
735735 CheckMethods cenv env baseValOpt overrides
736736
737- and CheckExprOp cenv env ( op , tyargs , args , m ) context =
737+ and CheckExprOp cenv env ( op , tyargs , args , m ) contextexpr =
738738let limitedCheck () =
739739if env.limitedthen errorR( Error( FSComp.SR.chkObjCtorsCantUseExceptionHandling(), m))
740740 List.iter( CheckTypePermitByrefs cenv env m) tyargs
@@ -828,13 +828,13 @@ and CheckExprOp cenv env (op,tyargs,args,m) context =
828828 CheckTypeInstNoByrefs cenv env m tyargs
829829
830830| TOp.ValFieldGetAddr rfref, tyargs,[] ->
831- if noByrefs context&& cenv.reportErrorsthen
831+ if noByrefs context&& cenv.reportErrors&& isByrefLikeTy cenv.g ( tyOfExpr cenv.g expr ) then
832832 errorR( Error( FSComp.SR.chkNoAddressStaticFieldAtThisPoint( rfref.FieldName), m))
833833 CheckTypeInstNoByrefs cenv env m tyargs
834834// NOTE: there are no arg exprs to check in this case
835835
836836| TOp.ValFieldGetAddr rfref, tyargs,[ rx] ->
837- if noByrefs context&& cenv.reportErrorsthen
837+ if noByrefs context&& cenv.reportErrors&& isByrefLikeTy cenv.g ( tyOfExpr cenv.g expr ) then
838838 errorR( Error( FSComp.SR.chkNoAddressFieldAtThisPoint( rfref.FieldName), m))
839839// This construct is used for &(rx.rfield) and &(rx->rfield). Relax to permit byref types for rx. [See Bug 1263].
840840 CheckTypeInstNoByrefs cenv env m tyargs
@@ -849,7 +849,7 @@ and CheckExprOp cenv env (op,tyargs,args,m) context =
849849 CheckExprPermitByref cenv env arg1// allow byref - it may be address-of-struct
850850
851851| TOp.UnionCaseFieldGetAddr( uref, _ idx), tyargs,[ rx] ->
852- if noByrefs context&& cenv.reportErrorsthen
852+ if noByrefs context&& cenv.reportErrors&& isByrefLikeTy cenv.g ( tyOfExpr cenv.g expr ) then
853853 errorR( Error( FSComp.SR.chkNoAddressFieldAtThisPoint( uref.CaseName), m))
854854 CheckTypeInstNoByrefs cenv env m tyargs
855855// allow rx to be byref here, for struct unions
@@ -870,12 +870,12 @@ and CheckExprOp cenv env (op,tyargs,args,m) context =
870870// permit byref for lhs lvalue of readonly value
871871 CheckExprPermitByref cenv env lhs
872872| [ I_ ldflda( fspec) | I_ ldsflda( fspec) ],[ lhs] ->
873- if noByrefs context&& cenv.reportErrorsthen
873+ if noByrefs context&& cenv.reportErrors&& isByrefLikeTy cenv.g ( tyOfExpr cenv.g expr ) then
874874 errorR( Error( FSComp.SR.chkNoAddressFieldAtThisPoint( fspec.Name), m))
875875// permit byref for lhs lvalue
876876 CheckExprPermitByref cenv env lhs
877877| [ I_ ldelema(_, isNativePtr,_,_) ], lhsArray:: indices->
878- if not ( isNativePtr ) && noByrefs context && cenv.reportErrors then
878+ if noByrefs context && cenv.reportErrors && not isNativePtr && isByrefLikeTy cenv.g ( tyOfExpr cenv.g expr ) then
879879 errorR( Error( FSComp.SR.chkNoAddressOfArrayElementAtThisPoint(), m))
880880// permit byref for lhs lvalue
881881 CheckExprPermitByref cenv env lhsArray
@@ -982,7 +982,7 @@ and CheckLambdas isTop (memInfo: ValMemberInfo option) cenv env inlined topValIn
982982| _ ->
983983// Permit byrefs for let x = ...
984984 CheckTypePermitByrefs cenv env m ety
985- if not inlined&& isByrefLikeTy cenv.g etythen
985+ if not inlined&& ( isByrefLikeTy cenv.g ety|| isNativePtrTy cenv.g ety ) then
986986// allow byref to occur as RHS of byref binding.
987987 CheckExprPermitByref cenv env e
988988else