Skip to content

Commit ed5736b

Browse files
committed
Symbols: add Mfv.ApparentEnclosingType
1 parent 6f66b01 commit ed5736b

File tree

5 files changed

+42
-14
lines changed

5 files changed

+42
-14
lines changed

Diff for: src/Compiler/Service/ServiceInterfaceStubGenerator.fs

+5-1
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,11 @@ module InterfaceStubGenerator =
351351
// Ordinary instance members
352352
| _, true, _, name -> name + parArgs
353353
// Ordinary functions or values
354-
| false, _, _, name when not (v.ApparentEnclosingEntity.HasAttribute<RequireQualifiedAccessAttribute>()) ->
354+
| false, _, _, name when
355+
v.ApparentEnclosingEntity
356+
|> Option.map _.HasAttribute<RequireQualifiedAccessAttribute>()
357+
|> Option.defaultValue false
358+
|> not ->
355359
name + " " + parArgs
356360
// Ordinary static members or things (?) that require fully qualified access
357361
| _, _, _, name -> name + parArgs

Diff for: src/Compiler/Symbols/Symbols.fs

+24-8
Original file line numberDiff line numberDiff line change
@@ -1713,20 +1713,36 @@ type FSharpMemberOrFunctionOrValue(cenv, d:FSharpMemberOrValData, item) =
17131713
| ParentNone -> None
17141714
| Parent p -> FSharpEntity(cenv, p) |> Some
17151715

1716-
member _.ApparentEnclosingEntity: FSharpEntity =
1716+
member _.ApparentEnclosingEntity: FSharpEntity option =
17171717
let createEntity (ttype: TType) =
1718-
let tcref, tyargs = destAppTy cenv.g ttype
1719-
FSharpEntity(cenv, tcref, tyargs)
1718+
match tryAppTy cenv.g ttype with
1719+
| ValueSome(tcref, tyargs) -> Some(FSharpEntity(cenv, tcref, tyargs))
1720+
| _ -> None
17201721

17211722
checkIsResolved()
1722-
match d with
1723+
1724+
match d with
17231725
| E e -> createEntity e.ApparentEnclosingType
17241726
| P p -> createEntity p.ApparentEnclosingType
17251727
| M m | C m -> createEntity m.ApparentEnclosingType
1726-
| V v ->
1727-
match v.ApparentEnclosingEntity with
1728-
| ParentNone -> invalidOp "the value or member doesn't have a logical parent"
1729-
| Parent p -> FSharpEntity(cenv, p)
1728+
| V v ->
1729+
1730+
match v.ApparentEnclosingEntity with
1731+
| ParentNone -> invalidOp "the value or member doesn't have a logical parent"
1732+
| Parent p -> Some(FSharpEntity(cenv, p))
1733+
1734+
member _.ApparentEnclosingType: FSharpType =
1735+
checkIsResolved()
1736+
1737+
match d with
1738+
| E e -> FSharpType(cenv, e.ApparentEnclosingType)
1739+
| P p -> FSharpType(cenv, p.ApparentEnclosingType)
1740+
| M m | C m -> FSharpType(cenv, m.ApparentEnclosingType)
1741+
| V v ->
1742+
1743+
match v.ApparentEnclosingEntity with
1744+
| ParentNone -> invalidOp "the value or member doesn't have a logical parent"
1745+
| Parent p -> FSharpType(cenv, generalizedTyconRef cenv.g p)
17301746

17311747
member _.GenericParameters =
17321748
checkIsResolved()

Diff for: src/Compiler/Symbols/Symbols.fsi

+4-1
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,10 @@ type FSharpMemberOrFunctionOrValue =
780780
member DeclaringEntity: FSharpEntity option
781781

782782
/// Get the logical enclosing entity, which for an extension member is type being extended
783-
member ApparentEnclosingEntity: FSharpEntity
783+
member ApparentEnclosingEntity: FSharpEntity option
784+
785+
/// Get the logical enclosing type, which for an extension member is type being extended
786+
member ApparentEnclosingType: FSharpType
784787

785788
/// Get the declaration location of the member, function or value
786789
member DeclarationLocation: range

Diff for: tests/FSharp.Compiler.Service.Tests/Common.fs

+5
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,11 @@ let getSymbolFullName (symbol: FSharpSymbol) =
409409
| :? FSharpField as field -> Some field.FullName
410410
| _ -> None
411411

412+
let tryGetEntityFullName (entity: FSharpEntity option) =
413+
entity
414+
|> Option.map _.FullName
415+
|> Option.defaultValue ""
416+
412417
let assertContainsSymbolWithName name source =
413418
getSymbols source
414419
|> Seq.choose getSymbolName

Diff for: tests/FSharp.Compiler.Service.Tests/ProjectAnalysisTests.fs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3297,9 +3297,9 @@ let ``Test Project23 property`` () =
32973297
extensionProps
32983298
|> Array.collect (fun f ->
32993299
[| if f.HasGetterMethod then
3300-
yield (f.DeclaringEntity.Value.FullName, f.ApparentEnclosingEntity.FullName, f.GetterMethod.CompiledName, f.GetterMethod.DeclaringEntity.Value.FullName, attribsOfSymbol f)
3300+
yield (f.DeclaringEntity.Value.FullName, tryGetEntityFullName f.ApparentEnclosingEntity, f.GetterMethod.CompiledName, f.GetterMethod.DeclaringEntity.Value.FullName, attribsOfSymbol f)
33013301
if f.HasSetterMethod then
3302-
yield (f.DeclaringEntity.Value.FullName, f.ApparentEnclosingEntity.FullName, f.SetterMethod.CompiledName, f.SetterMethod.DeclaringEntity.Value.FullName, attribsOfSymbol f)
3302+
yield (f.DeclaringEntity.Value.FullName, tryGetEntityFullName f.ApparentEnclosingEntity, f.SetterMethod.CompiledName, f.SetterMethod.DeclaringEntity.Value.FullName, attribsOfSymbol f)
33033303
|])
33043304
|> Array.toList
33053305

@@ -3342,9 +3342,9 @@ let ``Test Project23 extension properties' getters/setters should refer to the c
33423342
match x.Symbol with
33433343
| :? FSharpMemberOrFunctionOrValue as f ->
33443344
if f.HasGetterMethod then
3345-
yield (f.DeclaringEntity.Value.FullName, f.GetterMethod.DeclaringEntity.Value.FullName, f.ApparentEnclosingEntity.FullName, f.GetterMethod.ApparentEnclosingEntity.FullName, attribsOfSymbol f)
3345+
yield (f.DeclaringEntity.Value.FullName, f.GetterMethod.DeclaringEntity.Value.FullName, tryGetEntityFullName f.ApparentEnclosingEntity, tryGetEntityFullName f.GetterMethod.ApparentEnclosingEntity, attribsOfSymbol f)
33463346
if f.HasSetterMethod then
3347-
yield (f.DeclaringEntity.Value.FullName, f.SetterMethod.DeclaringEntity.Value.FullName, f.ApparentEnclosingEntity.FullName, f.SetterMethod.ApparentEnclosingEntity.FullName, attribsOfSymbol f)
3347+
yield (f.DeclaringEntity.Value.FullName, f.SetterMethod.DeclaringEntity.Value.FullName, tryGetEntityFullName f.ApparentEnclosingEntity, tryGetEntityFullName f.SetterMethod.ApparentEnclosingEntity, attribsOfSymbol f)
33483348
| _ -> ()
33493349
|])
33503350
|> Array.toList

0 commit comments

Comments
 (0)