Skip to content

Commit 55d8e33

Browse files
Implement FSharpMemberOrFunctionOrValue.IsBaseValue
1 parent eca5ce8 commit 55d8e33

File tree

3 files changed

+23
-8
lines changed

3 files changed

+23
-8
lines changed

src/fsharp/vs/Symbols.fs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,14 +1490,12 @@ and FSharpMemberOrFunctionOrValue(cenv, d:FSharpMemberOrValData, item) =
14901490
v.Attribs |> List.map (fun a -> FSharpAttribute(cenv, AttribInfo.FSAttribInfo(cenv.g, a)))
14911491
|> makeReadOnlyCollection
14921492

1493-
(*
14941493
/// Is this "base" in "base.M(...)"
14951494
member __.IsBaseValue =
14961495
if isUnresolved() then false else
14971496
match d with
14981497
| M _ | P _ | E _ -> false
1499-
| V v -> match v.BaseOrThisInfo with BaseVal -> true | _ -> false
1500-
*)
1498+
| V v -> v.BaseOrThisInfo = BaseVal
15011499

15021500
/// Is this the "x" in "type C() as x = ..."
15031501
member __.IsConstructorThisValue =

src/fsharp/vs/Symbols.fsi

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -698,10 +698,8 @@ and [<Class>] FSharpMemberOrFunctionOrValue =
698698
/// XML documentation signature for the value, used for .xml file lookup for compiled code
699699
member XmlDocSig: string
700700

701-
#if TODO
702701
/// Indicates if this is "base" in "base.M(...)"
703702
member IsBaseValue : bool
704-
#endif
705703

706704
/// Indicates if this is the "x" in "type C() as x = ..."
707705
member IsConstructorThisValue : bool

tests/service/ProjectAnalysisTests.fs

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4419,10 +4419,15 @@ module Project36 =
44194419
let dllName = Path.ChangeExtension(base2, ".dll")
44204420
let projFileName = Path.ChangeExtension(base2, ".fsproj")
44214421
let fileSource1 = """
4422+
type A(i:int) =
4423+
member x.Value = i
4424+
44224425
type B(i:int) as b =
4426+
inherit A(i*2)
44234427
let a = b.Overload(i)
44244428
member x.Overload() = a
44254429
member x.Overload(y: int) = y + y
4430+
member x.BaseValue = base.Value
44264431
44274432
let [<Literal>] lit = 1.0
44284433
let notLit = 1.0
@@ -4449,21 +4454,35 @@ let callToOverload = B(5).Overload(4)
44494454
| FSharpImplementationFileDeclaration.InitAction e -> e
44504455
| _ -> failwith "unexpected declaration"
44514456

4457+
[<Test>]
4458+
let ``Test project36 FSharpMemberOrFunctionOrValue.IsBaseValue`` () =
4459+
Project36.wholeProjectResults.GetAllUsesOfAllSymbols()
4460+
|> Async.RunSynchronously
4461+
|> Array.pick (fun (su:FSharpSymbolUse) ->
4462+
if su.Symbol.DisplayName = "base"
4463+
then Some (su.Symbol :?> FSharpMemberOrFunctionOrValue)
4464+
else None)
4465+
|> fun baseSymbol -> shouldEqual true baseSymbol.IsBaseValue
4466+
44524467
[<Test>]
44534468
let ``Test project36 FSharpMemberOrFunctionOrValue.IsConstructorThisValue & IsMemberThisValue`` () =
4454-
match Project36.getExpr 1 with
4469+
// Instead of checking the symbol uses directly, walk the typed tree to check
4470+
// the correct values are also visible from there. Also note you cannot use
4471+
// BasicPatterns.ThisValue in these cases, this is only used when the symbol
4472+
// is implicit in the constructor
4473+
match Project36.getExpr 4 with
44554474
| BasicPatterns.Let((b,_),_) ->
44564475
b.IsConstructorThisValue && not b.IsMemberThisValue
44574476
| _ -> failwith "unexpected expression"
44584477
|> shouldEqual true
44594478

4460-
match Project36.getExpr 2 with
4479+
match Project36.getExpr 5 with
44614480
| BasicPatterns.FSharpFieldGet(Some(BasicPatterns.Value x),_,_) ->
44624481
x.IsMemberThisValue && not x.IsConstructorThisValue
44634482
| _ -> failwith "unexpected expression"
44644483
|> shouldEqual true
44654484

4466-
match Project36.getExpr 3 with
4485+
match Project36.getExpr 6 with
44674486
| BasicPatterns.Call(_,_,_,_,[BasicPatterns.Value s;_]) ->
44684487
not s.IsMemberThisValue && not s.IsConstructorThisValue
44694488
| _ -> failwith "unexpected expression"

0 commit comments

Comments
 (0)