Skip to content

Commit 528d287

Browse files
authored
Merge pull request #15461 from dotnet/merges/main-to-release/net8
2 parents 80bfbb6 + d4e15a8 commit 528d287

File tree

5 files changed

+35
-18
lines changed

5 files changed

+35
-18
lines changed

src/Compiler/Checking/NicePrint.fs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1266,8 +1266,21 @@ module PrintTastMemberOrVals =
12661266
layoutTyconRef denv vref.MemberApparentEntity ^^ SepL.dot ^^ nameL
12671267
else
12681268
nameL
1269+
1270+
let memberHasSameTyparNameAsParentTypeTypars =
1271+
let parentTyparNames =
1272+
vref.DeclaringEntity.TyparsNoRange
1273+
|> Seq.choose (fun tp -> if tp.typar_id.idText = unassignedTyparName then None else Some tp.typar_id.idText)
1274+
|> set
1275+
niceMethodTypars
1276+
|> Seq.exists (fun tp -> parentTyparNames.Contains tp.typar_id.idText)
1277+
12691278
let typarOrderMismatch = isTyparOrderMismatch niceMethodTypars argInfos
1270-
let nameL = if denv.showTyparBinding || typarOrderMismatch then layoutTyparDecls denv nameL true niceMethodTypars else nameL
1279+
let nameL =
1280+
if denv.showTyparBinding || typarOrderMismatch || memberHasSameTyparNameAsParentTypeTypars then
1281+
layoutTyparDecls denv nameL true niceMethodTypars
1282+
else
1283+
nameL
12711284
let nameL = layoutAccessibility denv vref.Accessibility nameL
12721285
nameL
12731286

src/Compiler/Service/FSharpCheckerResults.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,14 +889,14 @@ type internal TypeCheckInfo
889889
match minfos with
890890
| [] -> CompletionItemKind.Method false
891891
| minfo :: _ -> CompletionItemKind.Method minfo.IsExtensionMember
892+
| Item.AnonRecdField _
892893
| Item.RecdField _
893894
| Item.Property _ -> CompletionItemKind.Property
894895
| Item.Event _ -> CompletionItemKind.Event
895896
| Item.ILField _
896897
| Item.Value _ -> CompletionItemKind.Field
897898
| Item.CustomOperation _ -> CompletionItemKind.CustomOperation
898899
// These items are not given a completion kind. This could be reviewed
899-
| Item.AnonRecdField _
900900
| Item.ActivePatternResult _
901901
| Item.CustomOperation _
902902
| Item.CtorGroup _
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
module V
2+
3+
type 'a Foo =
4+
{
5+
Bar: 'a array
6+
D: int
7+
}
8+
member _.Make1<'b> (array: 'a array) : 'a Foo = failwith "meh"
9+
member _.Make2<'a> (array: 'a array) : 'a Foo = failwith "meh"

tests/service/CompletionTests.fs

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,6 @@ let assertHasItemWithNames names (completionInfo: DeclarationListInfo) =
1717
for name in names do
1818
Assert.That(Set.contains name itemNames, name)
1919

20-
let assertHasExactlyNamesAndNothingElse names (completionInfo: DeclarationListInfo) =
21-
let itemNames = getCompletionItemNames completionInfo |> set
22-
let expectedNames = Set.ofList names
23-
24-
Assert.That(itemNames, Is.EqualTo expectedNames)
25-
26-
2720
[<Test>]
2821
let ``Expr - record - field 01 - anon module`` () =
2922
let info = getCompletionInfo "{ Fi }" (4, 3) """
@@ -62,12 +55,4 @@ let record = { Field = 1 }
6255
6356
{ }
6457
"""
65-
assertHasItemWithNames ["Field"; "record"] info
66-
67-
[<Test>]
68-
let ``Expr - array of anonymous records`` () =
69-
let info = getCompletionInfo "x[0]." (3, 6) """
70-
let x = [ {| Name = "foo" |} ]
71-
x[0].
72-
"""
73-
assertHasExactlyNamesAndNothingElse ["Name"; "Equals"; "GetHashCode"; "GetType"; "ToString"] info
58+
assertHasItemWithNames ["Field"; "record"] info

vsintegration/tests/FSharp.Editor.Tests/CompletionProviderTests.fs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,3 +1450,13 @@ let t2 (x: {| D: NestdRecTy; E: {| a: string |} |}) = {| x with E.a = "a"; D.B =
14501450
"let t2 (x: {| D: NestdRecTy; E: {| a: string |} |}) = {| x with E.a = \"a\"; D.",
14511451
[ "B"; "C" ]
14521452
)
1453+
1454+
[<Fact>]
1455+
let ``Anonymous record fields have higher priority than methods`` () =
1456+
let fileContents =
1457+
"""
1458+
let x = [ {| Goo = 1; Foo = "foo" |} ]
1459+
x[0].
1460+
"""
1461+
1462+
VerifyCompletionListExactly(fileContents, "x[0].", [ "Foo"; "Goo"; "Equals"; "GetHashCode"; "GetType"; "ToString" ])

0 commit comments

Comments
 (0)