@@ -599,27 +599,32 @@ and FSharpUnionCase(cenv, v: UnionCaseRef) =
599599
600600
601601and FSharpFieldData =
602- | Recd of RecdFieldRef
602+ | ILField of TcGlobals * ILFieldInfo
603+ | RecdOrClass of RecdFieldRef
603604 | Union of UnionCaseRef * int
604- member x.RecdField =
605+ member x.TryRecdField =
605606 match x with
606- | Recd v -> v.RecdField
607- | Union ( v, n) -> v.FieldByIndex( n)
607+ | RecdOrClass v -> v.RecdField |> Choice1Of2
608+ | Union ( v, n) -> v.FieldByIndex( n) |> Choice1Of2
609+ | ILField (_, f) -> f |> Choice2Of2
608610 member x.DeclaringTyconRef =
609611 match x with
610- | Recd v -> v.TyconRef
612+ | RecdOrClass v -> v.TyconRef
611613 | Union ( v,_) -> v.TyconRef
614+ | ILField ( g, f) -> tcrefOfAppTy g f.EnclosingType
612615
613616and FSharpField ( cenv , d : FSharpFieldData ) =
614617 inherit FSharpSymbol ( cenv,
615618 ( fun () ->
616619 match d with
617- | Recd v ->
620+ | RecdOrClass v ->
618621 checkEntityIsResolved v.TyconRef
619622 Item.RecdField( RecdFieldInfo( generalizeTypars v.TyconRef.TyparsNoRange, v))
620623 | Union ( v,_) ->
621624 // This is not correct: there is no "Item" for a named union case field
622- Item.UnionCase( UnionCaseInfo( generalizeTypars v.TyconRef.TyparsNoRange, v), false )),
625+ Item.UnionCase( UnionCaseInfo( generalizeTypars v.TyconRef.TyparsNoRange, v), false )
626+ | ILField (_, f) ->
627+ Item.ILField( f)),
623628 ( fun this thisCcu2 ad ->
624629 checkForCrossProjectAccessibility ( thisCcu2, ad) ( cenv.thisCcu, ( this :?> FSharpField) .Accessibility.Contents))
625630 //&&
@@ -629,23 +634,25 @@ and FSharpField(cenv, d: FSharpFieldData) =
629634 )
630635
631636 let isUnresolved () =
637+ entityIsUnresolved d.DeclaringTyconRef ||
632638 match d with
633- | Recd v -> entityIsUnresolved v.TyconRef || v.TryRecdField.IsNone
634- | Union ( v,_) -> entityIsUnresolved v.TyconRef || v.TryUnionCase.IsNone
639+ | RecdOrClass v -> v.TryRecdField.IsNone
640+ | Union ( v,_) -> v.TryUnionCase.IsNone
641+ | ILField _ -> false
635642
636643 let checkIsResolved () =
644+ checkEntityIsResolved d.DeclaringTyconRef
637645 match d with
638- | Recd v ->
639- checkEntityIsResolved v.TyconRef
646+ | RecdOrClass v ->
640647 if v.TryRecdField.IsNone then
641648 invalidOp ( sprintf " The record field '%s ' could not be found in the target type" v.FieldName)
642649 | Union ( v,_) ->
643- checkEntityIsResolved v.TyconRef
644650 if v.TryUnionCase.IsNone then
645651 invalidOp ( sprintf " The union case '%s ' could not be found in the target type" v.CaseName)
652+ | ILField _ -> ()
646653
647654 new ( cenv , ucref , n ) = FSharpField( cenv, FSharpFieldData.Union( ucref, n))
648- new ( cenv , rfref ) = FSharpField( cenv, FSharpFieldData.Recd ( rfref))
655+ new ( cenv , rfref ) = FSharpField( cenv, FSharpFieldData.RecdOrClass ( rfref))
649656
650657 member __.DeclaringEntity =
651658 FSharpEntity( cenv, d.DeclaringTyconRef)
@@ -655,82 +662,118 @@ and FSharpField(cenv, d: FSharpFieldData) =
655662
656663 member __.IsMutable =
657664 if isUnresolved() then false else
658- d.RecdField.IsMutable
665+ match d.TryRecdField with
666+ | Choice1Of2 r -> r.IsMutable
667+ | Choice2Of2 f -> not f.IsInitOnly
659668
660669 member __.IsLiteral =
661670 if isUnresolved() then false else
662- d.RecdField.LiteralValue.IsSome
671+ match d.TryRecdField with
672+ | Choice1Of2 r -> r.LiteralValue.IsSome
673+ | Choice2Of2 f -> f.LiteralValue.IsSome
663674
664675 member __.LiteralValue =
665- if isUnresolved()
666- then None
667- else getLiteralValue d.RecdField.LiteralValue
676+ if isUnresolved() then None else
677+ match d.TryRecdField with
678+ | Choice1Of2 r -> getLiteralValue r.LiteralValue
679+ | Choice2Of2 f -> f.LiteralValue |> Option.map AbstractIL.ILRuntimeWriter.convFieldInit
668680
669681 member __.IsVolatile =
670682 if isUnresolved() then false else
671- d.RecdField.IsVolatile
683+ match d.TryRecdField with
684+ | Choice1Of2 r -> r.IsVolatile
685+ | Choice2Of2 _ -> false // F# doesn't actually respect "volatile" from other assemblies in any case
672686
673687 member __.IsDefaultValue =
674688 if isUnresolved() then false else
675- d.RecdField.IsZeroInit
689+ match d.TryRecdField with
690+ | Choice1Of2 r -> r.IsZeroInit
691+ | Choice2Of2 _ -> false
676692
677693 member __.XmlDocSig =
678694 checkIsResolved()
679695 let xmlsig =
680696 match d with
681- | Recd v ->
697+ | RecdOrClass v ->
682698 let recd = RecdFieldInfo( generalizeTypars v.TyconRef.TyparsNoRange, v)
683699 ItemDescriptionsImpl.GetXmlDocSigOfRecdFieldInfo recd
684700 | Union ( v,_) ->
685701 let unionCase = UnionCaseInfo( generalizeTypars v.TyconRef.TyparsNoRange, v)
686702 ItemDescriptionsImpl.GetXmlDocSigOfUnionCaseInfo unionCase
703+ | ILField (_, f) ->
704+ ItemDescriptionsImpl.GetXmlDocSigOfILFieldInfo cenv.infoReader range0 f
687705 match xmlsig with
688706 | Some (_, docsig) -> docsig
689707 | _ -> " "
690708
691709 member __.XmlDoc =
692710 if isUnresolved() then XmlDoc.Empty |> makeXmlDoc else
693- d.RecdField.XmlDoc |> makeXmlDoc
711+ match d.TryRecdField with
712+ | Choice1Of2 r -> r.XmlDoc
713+ | Choice2Of2 _ -> XmlDoc.Empty
714+ |> makeXmlDoc
694715
695716 member __.FieldType =
696717 checkIsResolved()
697- FSharpType( cenv, d.RecdField.FormalType)
718+ let fty =
719+ match d.TryRecdField with
720+ | Choice1Of2 r -> r.FormalType
721+ | Choice2Of2 f -> f.FieldType( cenv.amap, range0)
722+ FSharpType( cenv, fty)
698723
699724 member __.IsStatic =
700725 if isUnresolved() then false else
701- d.RecdField.IsStatic
726+ match d.TryRecdField with
727+ | Choice1Of2 r -> r.IsStatic
728+ | Choice2Of2 f -> f.IsStatic
702729
703730 member __.Name =
704731 checkIsResolved()
705- d.RecdField.Name
732+ match d.TryRecdField with
733+ | Choice1Of2 r -> r.Name
734+ | Choice2Of2 f -> f.FieldName
706735
707736 member __.IsCompilerGenerated =
708737 if isUnresolved() then false else
709- d.RecdField.IsCompilerGenerated
738+ match d.TryRecdField with
739+ | Choice1Of2 r -> r.IsCompilerGenerated
740+ | Choice2Of2 _ -> false
710741
711742 member __.DeclarationLocation =
712743 checkIsResolved()
713- d.RecdField.Range
744+ match d.TryRecdField with
745+ | Choice1Of2 r -> r.Range
746+ | Choice2Of2 _ -> range0
714747
715748 member __.FieldAttributes =
716749 if isUnresolved() then makeReadOnlyCollection [] else
717- d.RecdField.FieldAttribs |> List.map ( fun a -> FSharpAttribute( cenv, AttribInfo.FSAttribInfo( cenv.g, a))) |> makeReadOnlyCollection
750+ match d.TryRecdField with
751+ | Choice1Of2 r -> r.FieldAttribs |> List.map ( fun a -> FSharpAttribute( cenv, AttribInfo.FSAttribInfo( cenv.g, a)))
752+ | Choice2Of2 _ -> []
753+ |> makeReadOnlyCollection
718754
719755 member __.PropertyAttributes =
720756 if isUnresolved() then makeReadOnlyCollection [] else
721- d.RecdField.PropertyAttribs |> List.map ( fun a -> FSharpAttribute( cenv, AttribInfo.FSAttribInfo( cenv.g, a))) |> makeReadOnlyCollection
757+ match d.TryRecdField with
758+ | Choice1Of2 r -> r.PropertyAttribs |> List.map ( fun a -> FSharpAttribute( cenv, AttribInfo.FSAttribInfo( cenv.g, a)))
759+ | Choice2Of2 _ -> []
760+ |> makeReadOnlyCollection
722761
723762 member __.Accessibility : FSharpAccessibility =
724763 if isUnresolved() then FSharpAccessibility( taccessPublic) else
725- FSharpAccessibility( d.RecdField.Accessibility)
764+ let access =
765+ match d.TryRecdField with
766+ | Choice1Of2 r -> r.Accessibility
767+ | Choice2Of2 _ -> taccessPublic
768+ FSharpAccessibility( access)
726769
727770 member private x.V = d
728771 override x.Equals ( other : obj ) =
729772 box x === other ||
730773 match other with
731774 | :? FSharpField as uc ->
732775 match d, uc.V with
733- | Recd r1, Recd r2 -> recdFieldRefOrder.Compare( r1, r2) = 0
776+ | RecdOrClass r1, RecdOrClass r2 -> recdFieldRefOrder.Compare( r1, r2) = 0
734777 | Union ( u1, n1), Union ( u2, n2) -> cenv.g.unionCaseRefEq u1 u2 && n1 = n2
735778 | _ -> false
736779 | _ -> false
@@ -1967,7 +2010,9 @@ type FSharpSymbol with
19672010 | Item.Value v -> FSharpMemberOrFunctionOrValue( cenv, V v, item) :> _
19682011 | Item.UnionCase ( uinfo,_) -> FSharpUnionCase( cenv, uinfo.UnionCaseRef) :> _
19692012 | Item.ExnCase tcref -> FSharpEntity( cenv, tcref) :>_
1970- | Item.RecdField rfinfo -> FSharpField( cenv, Recd rfinfo.RecdFieldRef) :> _
2013+ | Item.RecdField rfinfo -> FSharpField( cenv, RecdOrClass rfinfo.RecdFieldRef) :> _
2014+
2015+ | Item.ILField finfo -> FSharpField( cenv, ILField ( cenv.g, finfo)) :> _
19712016
19722017 | Item.Event einfo ->
19732018 FSharpMemberOrFunctionOrValue( cenv, E einfo, item) :> _
0 commit comments