Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not check assembly symbols equality by DefinitionRange and name #4662

Merged
merged 4 commits into from
Jun 12, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions src/fsharp/NameResolution.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1334,19 +1334,23 @@ let tyconRefDefnHash (_g: TcGlobals) (eref1:EntityRef) =
hash eref1.LogicalName

let tyconRefDefnEq g (eref1:EntityRef) (eref2: EntityRef) =
tyconRefEq g eref1 eref2
tyconRefEq g eref1 eref2 ||

// Signature items considered equal to implementation items
|| ((eref1.DefinitionRange = eref2.DefinitionRange || eref1.SigRange = eref2.SigRange) &&
(eref1.LogicalName = eref2.LogicalName))
eref1.DefinitionRange <> Range.rangeStartup && eref1.DefinitionRange <> Range.range0 && eref1.DefinitionRange <> Range.rangeCmdArgs &&
(eref1.DefinitionRange = eref2.DefinitionRange || eref1.SigRange = eref2.SigRange) &&
eref1.LogicalName = eref2.LogicalName

let valRefDefnHash (_g: TcGlobals) (vref1:ValRef)=
let valRefDefnHash (_g: TcGlobals) (vref1:ValRef) =
hash vref1.DisplayName

let valRefDefnEq g (vref1:ValRef) (vref2: ValRef) =
valRefEq g vref1 vref2
valRefEq g vref1 vref2 ||

// Signature items considered equal to implementation items
|| ((vref1.DefinitionRange = vref2.DefinitionRange || vref1.SigRange = vref2.SigRange)) &&
(vref1.LogicalName = vref2.LogicalName)
vref1.DefinitionRange <> Range.rangeStartup && vref1.DefinitionRange <> Range.range0 && vref1.DefinitionRange <> Range.rangeCmdArgs &&
(vref1.DefinitionRange = vref2.DefinitionRange || vref1.SigRange = vref2.SigRange) &&
vref1.LogicalName = vref2.LogicalName

let unionCaseRefDefnEq g (uc1:UnionCaseRef) (uc2: UnionCaseRef) =
uc1.CaseName = uc2.CaseName && tyconRefDefnEq g uc1.TyconRef uc2.TyconRef
Expand Down
50 changes: 50 additions & 0 deletions tests/service/CSharpProjectAnalysis.fs
Original file line number Diff line number Diff line change
Expand Up @@ -146,3 +146,53 @@ let _ = CSharpClass(0)
Seq.exists (fun (mfv : FSharpMemberOrFunctionOrValue) -> mfv.IsEffectivelySameAs ctor) members |> should be True
| None -> failwith "Expected Some for DeclaringEntity"

let getEntitiesUses source =
let csharpAssembly = PathRelativeToTestAssembly "CSharp_Analysis.dll"
let results, _ = getProjectReferences(source, [csharpAssembly], None, None)
results.GetAllUsesOfAllSymbols()
|> Async.RunSynchronously
|> Seq.choose (fun su ->
match su.Symbol with
| :? FSharpEntity as entity -> Some entity
| _ -> None)
|> List.ofSeq

[<Test>]
#if NETCOREAPP2_0
[<Ignore("SKIPPED: need to check if these tests can be enabled for .NET Core testing of FSharp.Compiler.Service")>]
#endif
let ``Different types with the same short name equality check`` () =
let source = """
module CtorTest

let (s1: System.String) = null
let (s2: FSharp.Compiler.Service.Tests.String) = null
"""

let stringSymbols =
getEntitiesUses source
|> List.filter (fun entity -> entity.LogicalName = "String")

match stringSymbols with
| e1 :: e2 :: [] -> e1.IsEffectivelySameAs(e2) |> should be False
| _ -> sprintf "Expecting two symbols, got %A" stringSymbols |> failwith

[<Test>]
#if NETCOREAPP2_0
[<Ignore("SKIPPED: need to check if these tests can be enabled for .NET Core testing of FSharp.Compiler.Service")>]
#endif
let ``Different namespaces with the same short name equality check`` () =
let source = """
module CtorTest

open System.Linq
open FSharp.Compiler.Service.Tests.Linq
"""

let stringSymbols =
getEntitiesUses source
|> List.filter (fun entity -> entity.LogicalName = "Linq")

match stringSymbols with
| e1 :: e2 :: [] -> e1.IsEffectivelySameAs(e2) |> should be False
| _ -> sprintf "Expecting two symbols, got %A" stringSymbols |> failwith
10 changes: 10 additions & 0 deletions tests/service/data/CSharp_Analysis/CSharpClass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,14 @@ public static int StaticMember()
}
}

public class String
{
}

namespace Linq
{
public class DummyClass
{
}
}
}