Skip to content

Commit 55dcf8b

Browse files
committed
Add IsInstanceMemberInCompiledCode
1 parent 7e7bcdd commit 55dcf8b

File tree

3 files changed

+66
-2
lines changed

3 files changed

+66
-2
lines changed

src/fsharp/vs/Symbols.fs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1404,6 +1404,15 @@ and FSharpMemberOrFunctionOrValue(cenv, d:FSharpMemberOrValData, item) =
14041404
| M m -> m.IsInstance
14051405
| V v -> v.IsInstanceMember
14061406

1407+
member v.IsInstanceMemberInCompiledCode =
1408+
if isUnresolved() then false else
1409+
v.IsInstanceMember &&
1410+
match d with
1411+
| E e -> match e.ArbitraryValRef with Some vref -> ValRefIsCompiledAsInstanceMember cenv.g vref | None -> true
1412+
| P p -> match p.ArbitraryValRef with Some vref -> ValRefIsCompiledAsInstanceMember cenv.g vref | None -> true
1413+
| M m -> match m.ArbitraryValRef with Some vref -> ValRefIsCompiledAsInstanceMember cenv.g vref | None -> true
1414+
| V vref -> ValRefIsCompiledAsInstanceMember cenv.g vref
1415+
14071416
member __.IsExtensionMember =
14081417
if isUnresolved() then false else
14091418
match d with

src/fsharp/vs/Symbols.fsi

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -731,6 +731,12 @@ and [<Class>] FSharpMemberOrFunctionOrValue =
731731
/// Indicates if this is an instance member, when seen from F#?
732732
member IsInstanceMember : bool
733733

734+
/// Indicates if this is an instance member in compiled code.
735+
///
736+
/// Explanatory note: some members such as IsNone and IsSome on types with UseNullAsTrueValue appear
737+
/// as instance members in F# code but are compiled as static members.
738+
member IsInstanceMemberInCompiledCode : bool
739+
734740
/// Indicates if this is an implicit constructor?
735741
member IsImplicitConstructor : bool
736742

tests/service/ProjectAnalysisTests.fs

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ let attribsOfSymbol (s:FSharpSymbol) =
8888
if v.IsImplicitConstructor then yield "ctor"
8989
if v.IsMutable then yield "mutable"
9090
if v.IsOverrideOrExplicitInterfaceImplementation then yield "overridemem"
91+
if v.IsInstanceMember && not v.IsInstanceMemberInCompiledCode then yield "funky"
9192
if v.IsExplicitInterfaceImplementation then yield "intfmem"
9293
// if v.IsConstructorThisValue then yield "ctorthis"
9394
// if v.IsMemberThisValue then yield "this"
@@ -202,7 +203,7 @@ let ``Test project1 whole project errors`` () =
202203
wholeProjectResults.Errors.[0].EndColumn |> shouldEqual 44
203204

204205
[<Test>]
205-
let ``Test project39 should have protected FullName and TryFullName return same results`` () =
206+
let ``Test Project1 should have protected FullName and TryFullName return same results`` () =
206207
let wholeProjectResults = checker.ParseAndCheckProject(Project1.options) |> Async.RunSynchronously
207208
let rec getFullNameComparisons (entity: FSharpEntity) =
208209
seq { if not entity.IsProvided && entity.Accessibility.IsPublic then
@@ -2907,7 +2908,7 @@ let ``Test Project19 all symbols`` () =
29072908
("DayOfWeek", "DayOfWeek", "file1", ((10, 15), (10, 24)), [],
29082909
["enum"; "valuetype"]);
29092910
("System", "System", "file1", ((10, 8), (10, 14)), [], ["namespace"]);
2910-
("field Monday", "Monday", "file1", ((10, 8), (10, 31)), [], ["field"; "mutable"; "static"; "1"]);
2911+
("field Monday", "Monday", "file1", ((10, 8), (10, 31)), [], ["field"; "static"; "1"]);
29112912
("val s", "s", "file1", ((10, 4), (10, 5)), ["defn"], ["val"]);
29122913
("Impl", "Impl", "file1", ((2, 7), (2, 11)), ["defn"], ["module"])|]
29132914

@@ -4630,6 +4631,9 @@ let ``Test project37 typeof and arrays in attribute constructor arguments`` () =
46304631
|> Seq.map (fun a -> a.AttributeType.CompiledName)
46314632
|> Array.ofSeq |> shouldEqual [| "AttrTestAttribute"; "AttrTest2Attribute" |]
46324633

4634+
//-----------------------------------------------------------
4635+
4636+
46334637
module Project38 =
46344638
open System.IO
46354639

@@ -4724,6 +4728,8 @@ let ``Test project38 abstract slot information`` () =
47244728
|]
47254729

47264730

4731+
//--------------------------------------------
4732+
47274733
module Project39 =
47284734
open System.IO
47294735

@@ -4802,3 +4808,46 @@ let ``Test project39 all symbols`` () =
48024808
[["'a"]; ["'a0"]; ["'a"; "'a0"]]),
48034809
("return", "'b"))]
48044810

4811+
4812+
//--------------------------------------------
4813+
4814+
module Project40 =
4815+
open System.IO
4816+
4817+
let fileName1 = Path.ChangeExtension(Path.GetTempFileName(), ".fs")
4818+
let base2 = Path.GetTempFileName()
4819+
let dllName = Path.ChangeExtension(base2, ".dll")
4820+
let projFileName = Path.ChangeExtension(base2, ".fsproj")
4821+
let fileSource1 = """
4822+
module M
4823+
4824+
let f (x: option<_>) = x.IsSome, x.IsNone
4825+
4826+
(*
4827+
[<CompilationRepresentation(CompilationRepresentationFlags.UseNullAsTrueValue)>]
4828+
type C =
4829+
| A
4830+
| B of string
4831+
member x.IsItAnA = match x with A -> true | B _ -> false
4832+
member x.IsItAnAMethod() = match x with A -> true | B _ -> false
4833+
4834+
let g (x: C) = x.IsItAnA,x.IsItAnAMethod()
4835+
*)
4836+
"""
4837+
4838+
File.WriteAllText(fileName1, fileSource1)
4839+
let fileNames = [fileName1]
4840+
let args = mkProjectCommandLineArgs (dllName, fileNames)
4841+
let options = checker.GetProjectOptionsFromCommandLineArgs (projFileName, args)
4842+
let cleanFileName a = if a = fileName1 then "file1" else "??"
4843+
4844+
[<Test>]
4845+
let ``Test Project40 all symbols`` () =
4846+
4847+
let wholeProjectResults = checker.ParseAndCheckProject(Project40.options) |> Async.RunSynchronously
4848+
let allSymbolUses = wholeProjectResults.GetAllUsesOfAllSymbols() |> Async.RunSynchronously
4849+
let allSymbolUsesInfo = [ for s in allSymbolUses -> s.Symbol.DisplayName, tups s.RangeAlternate, attribsOfSymbol s.Symbol ]
4850+
allSymbolUsesInfo |> shouldEqual
4851+
[]
4852+
4853+

0 commit comments

Comments
 (0)