@@ -599,27 +599,32 @@ and FSharpUnionCase(cenv, v: UnionCaseRef) =
599
599
600
600
601
601
and FSharpFieldData =
602
- | Recd of RecdFieldRef
602
+ | ILField of TcGlobals * ILFieldInfo
603
+ | RecdOrClass of RecdFieldRef
603
604
| Union of UnionCaseRef * int
604
- member x.RecdField =
605
+ member x.TryRecdField =
605
606
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
608
610
member x.DeclaringTyconRef =
609
611
match x with
610
- | Recd v -> v.TyconRef
612
+ | RecdOrClass v -> v.TyconRef
611
613
| Union ( v,_) -> v.TyconRef
614
+ | ILField ( g, f) -> tcrefOfAppTy g f.EnclosingType
612
615
613
616
and FSharpField ( cenv , d : FSharpFieldData ) =
614
617
inherit FSharpSymbol ( cenv,
615
618
( fun () ->
616
619
match d with
617
- | Recd v ->
620
+ | RecdOrClass v ->
618
621
checkEntityIsResolved v.TyconRef
619
622
Item.RecdField( RecdFieldInfo( generalizeTypars v.TyconRef.TyparsNoRange, v))
620
623
| Union ( v,_) ->
621
624
// 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)),
623
628
( fun this thisCcu2 ad ->
624
629
checkForCrossProjectAccessibility ( thisCcu2, ad) ( cenv.thisCcu, ( this :?> FSharpField) .Accessibility.Contents))
625
630
//&&
@@ -629,23 +634,25 @@ and FSharpField(cenv, d: FSharpFieldData) =
629
634
)
630
635
631
636
let isUnresolved () =
637
+ entityIsUnresolved d.DeclaringTyconRef ||
632
638
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
635
642
636
643
let checkIsResolved () =
644
+ checkEntityIsResolved d.DeclaringTyconRef
637
645
match d with
638
- | Recd v ->
639
- checkEntityIsResolved v.TyconRef
646
+ | RecdOrClass v ->
640
647
if v.TryRecdField.IsNone then
641
648
invalidOp ( sprintf " The record field '%s ' could not be found in the target type" v.FieldName)
642
649
| Union ( v,_) ->
643
- checkEntityIsResolved v.TyconRef
644
650
if v.TryUnionCase.IsNone then
645
651
invalidOp ( sprintf " The union case '%s ' could not be found in the target type" v.CaseName)
652
+ | ILField _ -> ()
646
653
647
654
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))
649
656
650
657
member __.DeclaringEntity =
651
658
FSharpEntity( cenv, d.DeclaringTyconRef)
@@ -655,82 +662,118 @@ and FSharpField(cenv, d: FSharpFieldData) =
655
662
656
663
member __.IsMutable =
657
664
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
659
668
660
669
member __.IsLiteral =
661
670
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
663
674
664
675
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
668
680
669
681
member __.IsVolatile =
670
682
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
672
686
673
687
member __.IsDefaultValue =
674
688
if isUnresolved() then false else
675
- d.RecdField.IsZeroInit
689
+ match d.TryRecdField with
690
+ | Choice1Of2 r -> r.IsZeroInit
691
+ | Choice2Of2 _ -> false
676
692
677
693
member __.XmlDocSig =
678
694
checkIsResolved()
679
695
let xmlsig =
680
696
match d with
681
- | Recd v ->
697
+ | RecdOrClass v ->
682
698
let recd = RecdFieldInfo( generalizeTypars v.TyconRef.TyparsNoRange, v)
683
699
ItemDescriptionsImpl.GetXmlDocSigOfRecdFieldInfo recd
684
700
| Union ( v,_) ->
685
701
let unionCase = UnionCaseInfo( generalizeTypars v.TyconRef.TyparsNoRange, v)
686
702
ItemDescriptionsImpl.GetXmlDocSigOfUnionCaseInfo unionCase
703
+ | ILField (_, f) ->
704
+ ItemDescriptionsImpl.GetXmlDocSigOfILFieldInfo cenv.infoReader range0 f
687
705
match xmlsig with
688
706
| Some (_, docsig) -> docsig
689
707
| _ -> " "
690
708
691
709
member __.XmlDoc =
692
710
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
694
715
695
716
member __.FieldType =
696
717
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)
698
723
699
724
member __.IsStatic =
700
725
if isUnresolved() then false else
701
- d.RecdField.IsStatic
726
+ match d.TryRecdField with
727
+ | Choice1Of2 r -> r.IsStatic
728
+ | Choice2Of2 f -> f.IsStatic
702
729
703
730
member __.Name =
704
731
checkIsResolved()
705
- d.RecdField.Name
732
+ match d.TryRecdField with
733
+ | Choice1Of2 r -> r.Name
734
+ | Choice2Of2 f -> f.FieldName
706
735
707
736
member __.IsCompilerGenerated =
708
737
if isUnresolved() then false else
709
- d.RecdField.IsCompilerGenerated
738
+ match d.TryRecdField with
739
+ | Choice1Of2 r -> r.IsCompilerGenerated
740
+ | Choice2Of2 _ -> false
710
741
711
742
member __.DeclarationLocation =
712
743
checkIsResolved()
713
- d.RecdField.Range
744
+ match d.TryRecdField with
745
+ | Choice1Of2 r -> r.Range
746
+ | Choice2Of2 _ -> range0
714
747
715
748
member __.FieldAttributes =
716
749
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
718
754
719
755
member __.PropertyAttributes =
720
756
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
722
761
723
762
member __.Accessibility : FSharpAccessibility =
724
763
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)
726
769
727
770
member private x.V = d
728
771
override x.Equals ( other : obj ) =
729
772
box x === other ||
730
773
match other with
731
774
| :? FSharpField as uc ->
732
775
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
734
777
| Union ( u1, n1), Union ( u2, n2) -> cenv.g.unionCaseRefEq u1 u2 && n1 = n2
735
778
| _ -> false
736
779
| _ -> false
@@ -1967,7 +2010,9 @@ type FSharpSymbol with
1967
2010
| Item.Value v -> FSharpMemberOrFunctionOrValue( cenv, V v, item) :> _
1968
2011
| Item.UnionCase ( uinfo,_) -> FSharpUnionCase( cenv, uinfo.UnionCaseRef) :> _
1969
2012
| 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)) :> _
1971
2016
1972
2017
| Item.Event einfo ->
1973
2018
FSharpMemberOrFunctionOrValue( cenv, E einfo, item) :> _
0 commit comments