Skip to content

Commit

Permalink
Symbols: add Mfv.ApparentEnclosingType
Browse files Browse the repository at this point in the history
  • Loading branch information
auduchinok committed Aug 6, 2024
1 parent 6f66b01 commit ed5736b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
6 changes: 5 additions & 1 deletion src/Compiler/Service/ServiceInterfaceStubGenerator.fs
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,11 @@ module InterfaceStubGenerator =
// Ordinary instance members
| _, true, _, name -> name + parArgs
// Ordinary functions or values
| false, _, _, name when not (v.ApparentEnclosingEntity.HasAttribute<RequireQualifiedAccessAttribute>()) ->
| false, _, _, name when
v.ApparentEnclosingEntity
|> Option.map _.HasAttribute<RequireQualifiedAccessAttribute>()
|> Option.defaultValue false
|> not ->
name + " " + parArgs
// Ordinary static members or things (?) that require fully qualified access
| _, _, _, name -> name + parArgs
Expand Down
32 changes: 24 additions & 8 deletions src/Compiler/Symbols/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1713,20 +1713,36 @@ type FSharpMemberOrFunctionOrValue(cenv, d:FSharpMemberOrValData, item) =
| ParentNone -> None
| Parent p -> FSharpEntity(cenv, p) |> Some

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

checkIsResolved()
match d with

match d with
| E e -> createEntity e.ApparentEnclosingType
| P p -> createEntity p.ApparentEnclosingType
| M m | C m -> createEntity m.ApparentEnclosingType
| V v ->
match v.ApparentEnclosingEntity with
| ParentNone -> invalidOp "the value or member doesn't have a logical parent"
| Parent p -> FSharpEntity(cenv, p)
| V v ->

match v.ApparentEnclosingEntity with
| ParentNone -> invalidOp "the value or member doesn't have a logical parent"
| Parent p -> Some(FSharpEntity(cenv, p))

member _.ApparentEnclosingType: FSharpType =
checkIsResolved()

match d with
| E e -> FSharpType(cenv, e.ApparentEnclosingType)
| P p -> FSharpType(cenv, p.ApparentEnclosingType)
| M m | C m -> FSharpType(cenv, m.ApparentEnclosingType)
| V v ->

match v.ApparentEnclosingEntity with
| ParentNone -> invalidOp "the value or member doesn't have a logical parent"
| Parent p -> FSharpType(cenv, generalizedTyconRef cenv.g p)

member _.GenericParameters =
checkIsResolved()
Expand Down
5 changes: 4 additions & 1 deletion src/Compiler/Symbols/Symbols.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -780,7 +780,10 @@ type FSharpMemberOrFunctionOrValue =
member DeclaringEntity: FSharpEntity option

/// Get the logical enclosing entity, which for an extension member is type being extended
member ApparentEnclosingEntity: FSharpEntity
member ApparentEnclosingEntity: FSharpEntity option

/// Get the logical enclosing type, which for an extension member is type being extended
member ApparentEnclosingType: FSharpType

/// Get the declaration location of the member, function or value
member DeclarationLocation: range
Expand Down
5 changes: 5 additions & 0 deletions tests/FSharp.Compiler.Service.Tests/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,11 @@ let getSymbolFullName (symbol: FSharpSymbol) =
| :? FSharpField as field -> Some field.FullName
| _ -> None

let tryGetEntityFullName (entity: FSharpEntity option) =
entity
|> Option.map _.FullName
|> Option.defaultValue ""

let assertContainsSymbolWithName name source =
getSymbols source
|> Seq.choose getSymbolName
Expand Down
8 changes: 4 additions & 4 deletions tests/FSharp.Compiler.Service.Tests/ProjectAnalysisTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3297,9 +3297,9 @@ let ``Test Project23 property`` () =
extensionProps
|> Array.collect (fun f ->
[| if f.HasGetterMethod then
yield (f.DeclaringEntity.Value.FullName, f.ApparentEnclosingEntity.FullName, f.GetterMethod.CompiledName, f.GetterMethod.DeclaringEntity.Value.FullName, attribsOfSymbol f)
yield (f.DeclaringEntity.Value.FullName, tryGetEntityFullName f.ApparentEnclosingEntity, f.GetterMethod.CompiledName, f.GetterMethod.DeclaringEntity.Value.FullName, attribsOfSymbol f)
if f.HasSetterMethod then
yield (f.DeclaringEntity.Value.FullName, f.ApparentEnclosingEntity.FullName, f.SetterMethod.CompiledName, f.SetterMethod.DeclaringEntity.Value.FullName, attribsOfSymbol f)
yield (f.DeclaringEntity.Value.FullName, tryGetEntityFullName f.ApparentEnclosingEntity, f.SetterMethod.CompiledName, f.SetterMethod.DeclaringEntity.Value.FullName, attribsOfSymbol f)
|])
|> Array.toList

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

0 comments on commit ed5736b

Please sign in to comment.