-
Notifications
You must be signed in to change notification settings - Fork 858
Allow interpolated string adjacent to '=' (e.g. C(Name=$"value")) #19820
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
Open
edgarfgp
wants to merge
4
commits into
dotnet:main
Choose a base branch
from
edgarfgp:fix-16696-equals-dollar-interpolated-string
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
98d38a4
Allow =$"..." (interpolated string adjacent to =) (#16696)
edgarfgp 0014e51
fix test name
edgarfgp 724607c
Merge branch 'main' into fix-16696-equals-dollar-interpolated-string
edgarfgp 26c12e7
Merge branch 'main' into fix-16696-equals-dollar-interpolated-string
edgarfgp File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -361,3 +361,107 @@ let s = $"{f.Invoke(42)}" | |
| """ | ||
| |> compileExeAndRun | ||
| |> shouldSucceed | ||
|
|
||
| [<Fact>] | ||
| let ``Issue 16696 - let-binding with =$"..." (no space)`` () = | ||
| Fsx """ | ||
| let n = 42 | ||
| let world = "world" | ||
| let plain =$"123" | ||
| let withHole =$"hello {world}" | ||
| let withTypedHole =$"%d{n}" | ||
| if plain <> "123" then failwithf "plain: expected 123, got %s" plain | ||
| if withHole <> "hello world" then failwithf "withHole: expected 'hello world', got %s" withHole | ||
| if withTypedHole <> "42" then failwithf "withTypedHole: expected 42, got %s" withTypedHole | ||
|
Comment on lines
+368
to
+375
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @edgarfgp Could you minimize the test, so it's clear what it tests? |
||
| """ | ||
| |> compileExeAndRun | ||
| |> shouldSucceed | ||
|
|
||
| [<Fact>] | ||
| let ``Issue 16696 - property initialization in constructor call with Name=$"..."`` () = | ||
| Fsx """ | ||
| type C() = | ||
| member val Name = "" with get, set | ||
|
|
||
| let n = 42 | ||
| let plain = C(Name=$"123") | ||
| let withHole = C(Name=$"items: %d{n}") | ||
|
|
||
| if plain.Name <> "123" then failwithf "plain: expected 123, got %s" plain.Name | ||
| if withHole.Name <> "items: 42" then failwithf "withHole: expected 'items: 42', got %s" withHole.Name | ||
| """ | ||
| |> compileExeAndRun | ||
| |> shouldSucceed | ||
|
|
||
| [<Fact>] | ||
| let ``Issue 16696 - record creation with Field=$"..."`` () = | ||
| Fsx """ | ||
| type R = { Name: string } | ||
| let n = 42 | ||
| let r1 = { Name=$"abc" } | ||
| let r2 = { Name=$"%d{n}" } | ||
| if r1.Name <> "abc" then failwithf "r1: expected abc, got %s" r1.Name | ||
| if r2.Name <> "42" then failwithf "r2: expected 42, got %s" r2.Name | ||
| """ | ||
| |> compileExeAndRun | ||
| |> shouldSucceed | ||
|
|
||
| [<Fact>] | ||
| let ``Issue 16696 - record copy with Field=$"..."`` () = | ||
| Fsx """ | ||
| type R = { Name: string; Count: int } | ||
| let n = 42 | ||
| let r = { Name = ""; Count = 1 } | ||
| let r1 = { r with Name=$"abc" } | ||
| let r2 = { r with Name=$"%d{n}" } | ||
| if r1.Name <> "abc" then failwithf "r1: expected abc, got %s" r1.Name | ||
| if r2.Name <> "42" then failwithf "r2: expected 42, got %s" r2.Name | ||
| """ | ||
| |> compileExeAndRun | ||
| |> shouldSucceed | ||
|
|
||
| [<Fact>] | ||
| let ``Issue 16696 - =$ followed by non-quote still rejected as deprecated operator`` () = | ||
| Fsx """ | ||
| let x =$abc | ||
| """ | ||
| |> compile | ||
| |> shouldFail | ||
| |> withDiagnosticMessageMatches "is not permitted as a character in operator names" | ||
|
|
||
| [<Fact>] | ||
| let ``Issue 16696 - defining (=$) as a custom operator is still rejected`` () = | ||
| Fsx """ | ||
| let (=$) a b = a + b | ||
| """ | ||
| |> compile | ||
| |> shouldFail | ||
| |> withDiagnosticMessageMatches "is not permitted as a character in operator names" | ||
|
|
||
| [<Fact>] | ||
| let ``Issue 16696 - =$ used as infix operator is still rejected`` () = | ||
| Fsx """ | ||
| let f a b = a =$ b | ||
| """ | ||
| |> compile | ||
| |> shouldFail | ||
| |> withDiagnosticMessageMatches "is not permitted as a character in operator names" | ||
|
|
||
| [<Fact>] | ||
| let ``Issue 16696 - verbatim interpolation form is still rejected (out of scope)`` () = | ||
| Fsx """ | ||
| let x =$@"abc" | ||
| """ | ||
| |> compile | ||
| |> shouldFail | ||
| |> withDiagnosticMessageMatches "is not permitted as a character in operator names" | ||
|
|
||
| [<Fact>] | ||
| let ``Issue 16696 - = $"..." (with space) still parses unchanged`` () = | ||
| Fsx """ | ||
| let n = 42 | ||
| let x = $"%d{n}" | ||
| if x <> "42" then failwithf "expected 42, got %s" x | ||
| """ | ||
| |> compileExeAndRun | ||
| |> shouldSucceed | ||
1 change: 1 addition & 0 deletions
1
tests/service/data/SyntaxTree/String/SynExprInterpolatedStringAdjacentEquals.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| let x =$"123" |
24 changes: 24 additions & 0 deletions
24
tests/service/data/SyntaxTree/String/SynExprInterpolatedStringAdjacentEquals.fs.bsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| ImplFile | ||
| (ParsedImplFileInput | ||
| ("/root/String/SynExprInterpolatedStringAdjacentEquals.fs", false, | ||
| QualifiedNameOfFile SynExprInterpolatedStringAdjacentEquals, [], | ||
| [SynModuleOrNamespace | ||
| ([SynExprInterpolatedStringAdjacentEquals], false, AnonModule, | ||
| [Let | ||
| (false, | ||
| [SynBinding | ||
| (None, Normal, false, false, [], | ||
| PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), | ||
| SynValData | ||
| (None, SynValInfo ([], SynArgInfo ([], false, None)), None), | ||
| Named (SynIdent (x, None), false, None, (1,4--1,5)), None, | ||
| InterpolatedString | ||
| ([String ("123", (1,7--1,13))], Regular, (1,7--1,13)), | ||
| (1,4--1,5), Yes (1,0--1,13), { LeadingKeyword = Let (1,0--1,3) | ||
| InlineKeyword = None | ||
| EqualsRange = Some (1,6--1,7) })], | ||
| (1,0--1,13), { InKeyword = None })], PreXmlDocEmpty, [], None, | ||
| (1,0--2,0), { LeadingKeyword = None })], (true, true), | ||
| { ConditionalDirectives = [] | ||
| WarnDirectives = [] | ||
| CodeComments = [] }, set [])) |
1 change: 1 addition & 0 deletions
1
tests/service/data/SyntaxTree/String/SynExprInterpolatedStringAdjacentEqualsTripleQuote.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| let x =$"""abc""" |
26 changes: 26 additions & 0 deletions
26
.../service/data/SyntaxTree/String/SynExprInterpolatedStringAdjacentEqualsTripleQuote.fs.bsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| ImplFile | ||
| (ParsedImplFileInput | ||
| ("/root/String/SynExprInterpolatedStringAdjacentEqualsTripleQuote.fs", | ||
| false, | ||
| QualifiedNameOfFile SynExprInterpolatedStringAdjacentEqualsTripleQuote, [], | ||
| [SynModuleOrNamespace | ||
| ([SynExprInterpolatedStringAdjacentEqualsTripleQuote], false, | ||
| AnonModule, | ||
| [Let | ||
| (false, | ||
| [SynBinding | ||
| (None, Normal, false, false, [], | ||
| PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), | ||
| SynValData | ||
| (None, SynValInfo ([], SynArgInfo ([], false, None)), None), | ||
| Named (SynIdent (x, None), false, None, (1,4--1,5)), None, | ||
| InterpolatedString | ||
| ([String ("abc", (1,7--1,17))], TripleQuote, (1,7--1,17)), | ||
| (1,4--1,5), Yes (1,0--1,17), { LeadingKeyword = Let (1,0--1,3) | ||
| InlineKeyword = None | ||
| EqualsRange = Some (1,6--1,7) })], | ||
| (1,0--1,17), { InKeyword = None })], PreXmlDocEmpty, [], None, | ||
| (1,0--2,0), { LeadingKeyword = None })], (true, true), | ||
| { ConditionalDirectives = [] | ||
| WarnDirectives = [] | ||
| CodeComments = [] }, set [])) |
2 changes: 2 additions & 0 deletions
2
tests/service/data/SyntaxTree/String/SynExprInterpolatedStringAdjacentEqualsWithHole.fs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| let n = 42 | ||
| let x =$"{n}" |
38 changes: 38 additions & 0 deletions
38
tests/service/data/SyntaxTree/String/SynExprInterpolatedStringAdjacentEqualsWithHole.fs.bsl
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| ImplFile | ||
| (ParsedImplFileInput | ||
| ("/root/String/SynExprInterpolatedStringAdjacentEqualsWithHole.fs", false, | ||
| QualifiedNameOfFile SynExprInterpolatedStringAdjacentEqualsWithHole, [], | ||
| [SynModuleOrNamespace | ||
| ([SynExprInterpolatedStringAdjacentEqualsWithHole], false, AnonModule, | ||
| [Let | ||
| (false, | ||
| [SynBinding | ||
| (None, Normal, false, false, [], | ||
| PreXmlDoc ((1,0), FSharp.Compiler.Xml.XmlDocCollector), | ||
| SynValData | ||
| (None, SynValInfo ([], SynArgInfo ([], false, None)), None), | ||
| Named (SynIdent (n, None), false, None, (1,4--1,5)), None, | ||
| Const (Int32 42, (1,8--1,10)), (1,4--1,5), Yes (1,0--1,10), | ||
| { LeadingKeyword = Let (1,0--1,3) | ||
| InlineKeyword = None | ||
| EqualsRange = Some (1,6--1,7) })], (1,0--1,10), | ||
| { InKeyword = None }); | ||
| Let | ||
| (false, | ||
| [SynBinding | ||
| (None, Normal, false, false, [], | ||
| PreXmlDoc ((2,0), FSharp.Compiler.Xml.XmlDocCollector), | ||
| SynValData | ||
| (None, SynValInfo ([], SynArgInfo ([], false, None)), None), | ||
| Named (SynIdent (x, None), false, None, (2,4--2,5)), None, | ||
| InterpolatedString | ||
| ([String ("", (2,7--2,10)); FillExpr (Ident n, None); | ||
| String ("", (2,11--2,13))], Regular, (2,7--2,13)), | ||
| (2,4--2,5), Yes (2,0--2,13), { LeadingKeyword = Let (2,0--2,3) | ||
| InlineKeyword = None | ||
| EqualsRange = Some (2,6--2,7) })], | ||
| (2,0--2,13), { InKeyword = None })], PreXmlDocEmpty, [], None, | ||
| (1,0--3,0), { LeadingKeyword = None })], (true, true), | ||
| { ConditionalDirectives = [] | ||
| WarnDirectives = [] | ||
| CodeComments = [] }, set [])) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@edgarfgp What other implications may this change bring? Have you considered following approach used for operators and type arguments?