Skip to content

Commit dcfd9f8

Browse files
Add tests for some FSharpMemberOrFunctionOrValue properties
1 parent 5b48c32 commit dcfd9f8

File tree

3 files changed

+79
-2
lines changed

3 files changed

+79
-2
lines changed

src/fsharp/vs/Symbols.fs

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

1493-
1493+
(*
14941494
/// Is this "base" in "base.M(...)"
14951495
member __.IsBaseValue =
14961496
if isUnresolved() then false else
14971497
match d with
14981498
| M _ | P _ | E _ -> false
14991499
| V v -> match v.BaseOrThisInfo with BaseVal -> true | _ -> false
1500-
1500+
*)
15011501

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

src/fsharp/vs/Symbols.fsi

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -698,8 +698,10 @@ 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
701702
/// Indicates if this is "base" in "base.M(...)"
702703
member IsBaseValue : bool
704+
#endif
703705

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

tests/service/ProjectAnalysisTests.fs

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,9 @@ let attribsOfSymbol (s:FSharpSymbol) =
8888
if v.IsMutable then yield "mutable"
8989
if v.IsOverrideOrExplicitInterfaceImplementation then yield "overridemem"
9090
if v.IsExplicitInterfaceImplementation then yield "intfmem"
91+
// if v.IsConstructorThisValue then yield "ctorthis"
92+
// if v.IsMemberThisValue then yield "this"
93+
// if v.LiteralValue.IsSome then yield "literal"
9194
| _ -> () ]
9295

9396
module Project1 =
@@ -4408,3 +4411,75 @@ let ``Test project35 CurriedParameterGroups should be available for nested funct
44084411

44094412
| _ -> failwith "Unexpected symbol type"
44104413

4414+
module Project36 =
4415+
open System.IO
4416+
4417+
let fileName1 = Path.ChangeExtension(Path.GetTempFileName(), ".fs")
4418+
let base2 = Path.GetTempFileName()
4419+
let dllName = Path.ChangeExtension(base2, ".dll")
4420+
let projFileName = Path.ChangeExtension(base2, ".fsproj")
4421+
let fileSource1 = """
4422+
type B(i:int) as b =
4423+
let a = b.Overload(i)
4424+
member x.Overload() = a
4425+
member x.Overload(y: int) = y + y
4426+
4427+
let [<Literal>] lit = 1.0
4428+
let notLit = 1.0
4429+
let callToOverload = B(5).Overload(4)
4430+
"""
4431+
File.WriteAllText(fileName1, fileSource1)
4432+
let cleanFileName a = if a = fileName1 then "file1" else "??"
4433+
4434+
let fileNames = [fileName1]
4435+
let args = mkProjectCommandLineArgs (dllName, fileNames)
4436+
let keepAssemblyContentsChecker = FSharpChecker.Create(keepAssemblyContents=true)
4437+
let options = keepAssemblyContentsChecker.GetProjectOptionsFromCommandLineArgs (projFileName, args)
4438+
let wholeProjectResults =
4439+
keepAssemblyContentsChecker.ParseAndCheckProject(options)
4440+
|> Async.RunSynchronously
4441+
let declarations =
4442+
let checkedFile = wholeProjectResults.AssemblyContents.ImplementationFiles.[0]
4443+
match checkedFile.Declarations.[0] with
4444+
| FSharpImplementationFileDeclaration.Entity (_, subDecls) -> subDecls
4445+
| _ -> failwith "unexpected"
4446+
let getExpr exprIndex =
4447+
match declarations.[exprIndex] with
4448+
| FSharpImplementationFileDeclaration.MemberOrFunctionOrValue(_,_,e) -> e
4449+
| FSharpImplementationFileDeclaration.InitAction e -> e
4450+
| _ -> failwith "unexpected"
4451+
4452+
[<Test>]
4453+
let ``Test project36 FSharpMemberOrFunctionOrValue properties`` () =
4454+
match Project36.getExpr 1 with
4455+
| BasicPatterns.Let((b,_),_)
4456+
when b.IsConstructorThisValue && not b.IsMemberThisValue -> ()
4457+
| _ -> failwith "val b in type B constructor must be ConstructorThis"
4458+
4459+
match Project36.getExpr 2 with
4460+
| BasicPatterns.FSharpFieldGet(Some(BasicPatterns.Value x),_,_)
4461+
when x.IsMemberThisValue && not x.IsConstructorThisValue -> ()
4462+
| _ -> failwith "val x in B.Overload() must be MemberThis"
4463+
4464+
match Project36.getExpr 3 with
4465+
| BasicPatterns.Call(_,_,_,_,[BasicPatterns.Value s;_])
4466+
when not s.IsMemberThisValue && not s.IsConstructorThisValue -> ()
4467+
| _ -> failwith "val s in B.Overload(s) must not be MemberThis"
4468+
4469+
let project36Module = Project36.wholeProjectResults.AssemblySignature.Entities.[0]
4470+
let lit = project36Module.MembersFunctionsAndValues.[0]
4471+
let notLit = project36Module.MembersFunctionsAndValues.[1]
4472+
if lit.LiteralValue.IsNone || notLit.LiteralValue.IsSome then
4473+
failwith "val lit must be LiteralValue while notLit musn't"
4474+
4475+
[<Test>]
4476+
let ``Test project36 FSharpMemberOrFunctionOrValue.Overloads(false)`` () =
4477+
match Project36.getExpr 6 with
4478+
| BasicPatterns.Call(_,meth,_,_,_)->
4479+
if meth.Overloads(false).IsSome then ()
4480+
else failwithf "Cannot check method %s is overloaded from typed expression" meth.FullName
4481+
| _ -> failwith "unexpected"
4482+
4483+
let typeB = Project36.wholeProjectResults.AssemblySignature.Entities.[0].NestedEntities.[0]
4484+
if typeB.MembersFunctionsAndValues.[2].Overloads(false).Value.Count < 2 then
4485+
failwith "type B has two overloaded methods named Overload"

0 commit comments

Comments
 (0)