Skip to content

Commit

Permalink
Merge pull request #16000 from dotnet/merges/main-to-release/dev17.8
Browse files Browse the repository at this point in the history
  • Loading branch information
vzarytovskii authored Sep 20, 2023
2 parents c544e6d + 920f639 commit 767ffa7
Show file tree
Hide file tree
Showing 43 changed files with 551 additions and 67 deletions.
36 changes: 22 additions & 14 deletions src/Compiler/Service/FSharpCheckerResults.fs
Original file line number Diff line number Diff line change
Expand Up @@ -986,24 +986,32 @@ type internal TypeCheckInfo
None

/// Suggest name based on type
let SuggestNameBasedOnType g pos ty =
if isNumericType g ty then
CreateCompletionItemForSuggestedPatternName pos "num"
else
match tryTcrefOfAppTy g ty with
| ValueSome tcref when not (tyconRefEq g g.system_Object_tcref tcref) ->
CreateCompletionItemForSuggestedPatternName pos tcref.DisplayName
| _ -> None
let SuggestNameBasedOnType (g: TcGlobals) pos ty =
match stripTyparEqns ty with
| TType_app (tyconRef = tcref) when tcref.IsTypeAbbrev && (tcref.IsLocalRef || not (ccuEq g.fslibCcu tcref.nlr.Ccu)) ->
// Respect user-defined aliases
CreateCompletionItemForSuggestedPatternName pos tcref.DisplayName
| ty ->
if isNumericType g ty then
CreateCompletionItemForSuggestedPatternName pos "num"
else
match tryTcrefOfAppTy g ty with
| ValueSome tcref when not (tyconRefEq g g.system_Object_tcref tcref) ->
CreateCompletionItemForSuggestedPatternName pos tcref.DisplayName
| _ -> None

/// Suggest names based on field name and type, add them to the list
let SuggestNameForUnionCaseFieldPattern g caseIdPos fieldPatternPos (uci: UnionCaseInfo) indexOrName completions =
let SuggestNameForUnionCaseFieldPattern g caseIdPos fieldPatternPos (uci: UnionCaseInfo) indexOrName isTheOnlyField completions =
let field =
match indexOrName with
| Choice1Of2 index ->
// Index is None when parentheses were not used, i.e. "| Some v ->" - suggest a name only when the case has a single field
match uci.UnionCase.RecdFieldsArray, index with
| [| field |], None -> Some field
| [| _ |], Some _
| [| field |], None ->
// Index is None when parentheses were not used, i.e. `| Some v ->` - suggest a name only when the case has a single field
Some field
| [| _ |], Some _ when not isTheOnlyField ->
// When completing `| Some (a| , b)`, we're binding the first tuple element, not the sole case field
None
| _, None -> None
| arr, Some index -> arr |> Array.tryItem index
| Choice2Of2 name -> uci.UnionCase.RecdFieldsArray |> Array.tryFind (fun x -> x.DisplayName = name)
Expand All @@ -1016,7 +1024,7 @@ type internal TypeCheckInfo
sResolutions.CapturedNameResolutions
|> ResizeArray.tryPick (fun r ->
match r.Item with
| Item.Value vref when r.Pos = fieldPatternPos -> Some(stripTyparEqns vref.Type)
| Item.Value vref when r.Pos = fieldPatternPos -> Some vref.Type
| _ -> None)
|> Option.defaultValue field.FormalType
else
Expand Down Expand Up @@ -1118,7 +1126,7 @@ type internal TypeCheckInfo
|> Option.defaultValue []
|> List.append (fields indexOrName isTheOnlyField uci)

Some(SuggestNameForUnionCaseFieldPattern g caseIdRange.End pos uci indexOrName list, r.DisplayEnv, r.Range)
Some(SuggestNameForUnionCaseFieldPattern g caseIdRange.End pos uci indexOrName isTheOnlyField list, r.DisplayEnv, r.Range)
| _ -> None)
|> Option.orElse declaredItems

Expand Down
14 changes: 14 additions & 0 deletions src/Compiler/pars.fsy
Original file line number Diff line number Diff line change
Expand Up @@ -5356,6 +5356,20 @@ recdExprCore:
(None, l)
| _ -> raiseParseErrorAt (rhs parseState 2) (FSComp.SR.parsFieldBinding()) }

| appExpr EQUALS recover
{ match $1 with
| LongOrSingleIdent(false, (SynLongIdent _ as f), None, m) ->
let f = mkRecdField f
let mEquals = rhs parseState 2
let l = rebindRanges (f, Some mEquals, None) [] None
None, l
| _ -> raiseParseErrorAt (rhs parseState 2) (FSComp.SR.parsFieldBinding ()) }

| appExpr
{ let mExpr = rhs parseState 1
reportParseErrorAt mExpr (FSComp.SR.parsFieldBinding ())
Some($1, (mExpr.EndRange, None)), [] }

/*
handles cases when identifier can start from the underscore
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ ImplFile
(AnonRecd
(true, None, [], (4,0--4,12), { OpeningBraceRange = (4,7--4,9) }),
(4,0--4,12));
Expr (ArbitraryAfterError ("braceBarExpr", (5,0--5,10)), (5,0--5,10));
Expr (ArbitraryAfterError ("braceBarExpr", (6,0--6,17)), (6,0--6,17))],
Expr
(AnonRecd
(false, Some (Null (5,3--5,7), ((5,7--5,7), None)), [],
(5,0--5,10), { OpeningBraceRange = (5,0--5,2) }), (5,0--5,10));
Expr
(AnonRecd
(true, Some (Null (6,10--6,14), ((6,14--6,14), None)), [],
(6,0--6,17), { OpeningBraceRange = (6,7--6,9) }), (6,0--6,17))],
PreXmlDocEmpty, [], None, (1,0--6,17), { LeadingKeyword = None })],
(true, true), { ConditionalDirectives = []
CodeComments = [] }, set []))

(5,8)-(5,10) parse error Unexpected symbol '|}' in definition
(6,15)-(6,17) parse error Unexpected symbol '|}' in expression
(5,3)-(5,7) parse error Field bindings must have the form 'id = expr;'
(6,10)-(6,14) parse error Field bindings must have the form 'id = expr;'
(1,0)-(2,0) parse warning The declarations in this file will be placed in an implicit module 'AnonymousRecords-01' based on the file name 'AnonymousRecords-01.fs'. However this is not a valid F# identifier, so the contents will not be accessible from other files. Consider renaming the file or adding a 'module' or 'namespace' declaration at the top of the file.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

3 changes: 3 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 01.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

{| F = 1 |}
16 changes: 16 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 01.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Record - Anon 01.fs", false, QualifiedNameOfFile Module,
[], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(AnonRecd
(false, None,
[(SynLongIdent ([F], [], [None]), Some (3,5--3,6),
Const (Int32 1, (3,7--3,8)))], (3,0--3,11),
{ OpeningBraceRange = (3,0--3,2) }), (3,0--3,11))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,11), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))
3 changes: 3 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 02.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

{| F = |}
18 changes: 18 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 02.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Record - Anon 02.fs", false, QualifiedNameOfFile Module,
[], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(AnonRecd
(false, None,
[(SynLongIdent ([F], [], [None]), Some (3,5--3,6),
ArbitraryAfterError ("anonField", (3,3--3,4)))], (3,0--3,9),
{ OpeningBraceRange = (3,0--3,2) }), (3,0--3,9))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,9), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(3,7)-(3,9) parse error Unexpected symbol '|}' in definition
3 changes: 3 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 03.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

{| F |}
16 changes: 16 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 03.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Record - Anon 03.fs", false, QualifiedNameOfFile Module,
[], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(AnonRecd
(false, Some (Ident F, ((3,4--3,4), None)), [], (3,0--3,7),
{ OpeningBraceRange = (3,0--3,2) }), (3,0--3,7))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,7), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(3,3)-(3,4) parse error Field bindings must have the form 'id = expr;'
3 changes: 3 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 04.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

{| f() |}
20 changes: 20 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 04.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Record - Anon 04.fs", false, QualifiedNameOfFile Module,
[], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(AnonRecd
(false,
Some
(App
(Atomic, false, Ident f, Const (Unit, (3,4--3,6)),
(3,3--3,6)), ((3,6--3,6), None)), [], (3,0--3,9),
{ OpeningBraceRange = (3,0--3,2) }), (3,0--3,9))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,9), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(3,3)-(3,6) parse error Field bindings must have the form 'id = expr;'
3 changes: 3 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 05.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

{| f(). |}
23 changes: 23 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 05.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Record - Anon 05.fs", false, QualifiedNameOfFile Module,
[], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(AnonRecd
(false,
Some
(DiscardAfterMissingQualificationAfterDot
(App
(Atomic, false, Ident f, Const (Unit, (3,4--3,6)),
(3,3--3,6)), (3,6--3,7), (3,3--3,7)),
((3,10--3,10), None)), [], (3,0--3,10),
{ OpeningBraceRange = (3,0--3,2) }), (3,0--3,10))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,10), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(3,6)-(3,7) parse error Missing qualification after '.'
(3,3)-(3,10) parse error Field bindings must have the form 'id = expr;'
3 changes: 3 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 06.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module Module

{| f().F |}
23 changes: 23 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 06.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Record - Anon 06.fs", false, QualifiedNameOfFile Module,
[], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(AnonRecd
(false,
Some
(DotGet
(App
(Atomic, false, Ident f, Const (Unit, (3,4--3,6)),
(3,3--3,6)), (3,6--3,7),
SynLongIdent ([F], [], [None]), (3,3--3,8)),
((3,8--3,8), None)), [], (3,0--3,11),
{ OpeningBraceRange = (3,0--3,2) }), (3,0--3,11))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--3,11), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(3,3)-(3,8) parse error Field bindings must have the form 'id = expr;'
4 changes: 4 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 07.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Module

{| F1 = 1
F2 = |}
20 changes: 20 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 07.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Record - Anon 07.fs", false, QualifiedNameOfFile Module,
[], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(AnonRecd
(false, None,
[(SynLongIdent ([F1], [], [None]), Some (3,6--3,7),
Const (Int32 1, (3,8--3,9)));
(SynLongIdent ([F2], [], [None]), Some (4,6--4,7),
ArbitraryAfterError ("anonField", (4,3--4,5)))], (3,0--4,10),
{ OpeningBraceRange = (3,0--3,2) }), (3,0--4,10))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--4,10), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(4,3)-(4,5) parse error Field bindings must have the form 'id = expr;'
4 changes: 4 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 08.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module Module

{| F1 = 1
F2 |}
20 changes: 20 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 08.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Record - Anon 08.fs", false, QualifiedNameOfFile Module,
[], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(AnonRecd
(false, None,
[(SynLongIdent ([F1], [], [None]), Some (3,6--3,7),
Const (Int32 1, (3,8--3,9)));
(SynLongIdent ([F2], [], [None]), None,
ArbitraryAfterError ("anonField", (4,3--4,5)))], (3,0--4,8),
{ OpeningBraceRange = (3,0--3,2) }), (3,0--4,8))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--4,8), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))

(4,3)-(4,5) parse error Field bindings must have the form 'id = expr;'
5 changes: 5 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 09.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Module

{| F1 = 1
F2 =
F3 = 3 |}
27 changes: 27 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 09.fs.bsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
ImplFile
(ParsedImplFileInput
("/root/Expression/Record - Anon 09.fs", false, QualifiedNameOfFile Module,
[], [],
[SynModuleOrNamespace
([Module], false, NamedModule,
[Expr
(AnonRecd
(false, None,
[(SynLongIdent ([F1], [], [None]), Some (3,6--3,7),
Const (Int32 1, (3,8--3,9)));
(SynLongIdent ([F2], [], [None]), Some (4,6--4,7),
App
(NonAtomic, false,
App
(NonAtomic, true,
LongIdent
(false,
SynLongIdent
([op_Equality], [], [Some (OriginalNotation "=")]),
None, (5,6--5,7)), Ident F3, (5,3--5,7)),
Const (Int32 3, (5,8--5,9)), (5,3--5,9)))], (3,0--5,12),
{ OpeningBraceRange = (3,0--3,2) }), (3,0--5,12))],
PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), [], None,
(1,0--5,12), { LeadingKeyword = Module (1,0--1,6) })], (true, true),
{ ConditionalDirectives = []
CodeComments = [] }, set []))
5 changes: 5 additions & 0 deletions tests/service/data/SyntaxTree/Expression/Record - Anon 10.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
module Module

{| F1 = 1
F2
F3 = 3 |}
Loading

0 comments on commit 767ffa7

Please sign in to comment.