-
Notifications
You must be signed in to change notification settings - Fork 861
Warning 20 range: also walk through let/use bindings (follow-up to #19504) #19896
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -176,7 +176,7 @@ while x < 1 do | |
| |> withSingleDiagnostic (Warning 20, Line 6, Col 5, Line 6, Col 9, | ||
| "The result of this expression has type 'bool' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.") | ||
|
|
||
| // https://github.com/dotnet/fsharp/issues/5735 | ||
| // https://github.com/dotnet/fsharp/issues/5418 | ||
|
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. These comments are also redundant: the resulting commit is going to have the link to the PR with all the needed context. |
||
| [<Fact>] | ||
| let ``Warn On Last Expression In For Loop - int``() = | ||
| FSharp """ | ||
|
|
@@ -192,7 +192,7 @@ for i in 1 .. 10 do | |
| |> withSingleDiagnostic (Warning 20, Line 7, Col 5, Line 7, Col 8, | ||
| "The result of this expression has type 'int' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.") | ||
|
|
||
| // https://github.com/dotnet/fsharp/issues/5735 | ||
| // https://github.com/dotnet/fsharp/issues/5418 | ||
| [<Fact>] | ||
| let ``Warn On Last Expression In For Loop - string``() = | ||
| FSharp """ | ||
|
|
@@ -205,7 +205,7 @@ for i in 1 .. 10 do | |
| |> withSingleDiagnostic (Warning 20, Line 4, Col 5, Line 4, Col 12, | ||
| "The result of this expression has type 'string' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.") | ||
|
|
||
| // https://github.com/dotnet/fsharp/issues/5735 | ||
| // https://github.com/dotnet/fsharp/issues/5418 | ||
| [<Fact>] | ||
| let ``Warn On Last Expression In Integer For Loop``() = | ||
| FSharp """ | ||
|
|
@@ -218,7 +218,7 @@ for i = 1 to 10 do | |
| |> withSingleDiagnostic (Warning 20, Line 4, Col 5, Line 4, Col 7, | ||
| "The result of this expression has type 'int' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.") | ||
|
|
||
| // https://github.com/dotnet/fsharp/issues/5735 | ||
| // https://github.com/dotnet/fsharp/issues/5418 | ||
| [<Fact>] | ||
| let ``Warn On Last Expression In While Loop - non-bool``() = | ||
| FSharp """ | ||
|
|
@@ -233,6 +233,33 @@ while x < 1 do | |
| |> withSingleDiagnostic (Warning 20, Line 6, Col 5, Line 6, Col 8, | ||
| "The result of this expression has type 'int' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.") | ||
|
|
||
| // https://github.com/dotnet/fsharp/issues/5418 | ||
| [<Fact>] | ||
| let ``Warn On Last Expression In For Loop - non-unit after let binding``() = | ||
| FSharp """ | ||
| for _ in [] do | ||
| let x = 1 | ||
| x | ||
| """ | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withSingleDiagnostic (Warning 20, Line 4, Col 5, Line 4, Col 6, | ||
| "The result of this expression has type 'int' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.") | ||
|
|
||
| // https://github.com/dotnet/fsharp/issues/5418 | ||
| [<Fact>] | ||
| let ``Warn On Last Expression In For Loop - non-unit after nested let bindings``() = | ||
| FSharp """ | ||
| for _ in 1 .. 3 do | ||
| let a = 1 | ||
| let b = 2 | ||
| a + b | ||
| """ | ||
| |> typecheck | ||
| |> shouldFail | ||
| |> withSingleDiagnostic (Warning 20, Line 5, Col 5, Line 5, Col 10, | ||
| "The result of this expression has type 'int' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.") | ||
|
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. [Test Coverage / LOW] The PR title and release note both say "let/use", but the two new tests only cover Suggested addition: // https://github.com/dotnet/fsharp/issues/5418
[<Fact>]
let ``Warn On Last Expression In For Loop - non-unit after use binding``() =
FSharp """
type D() =
interface System.IDisposable with
member _.Dispose() = ()
member _.Value = 1
for _ in [] do
use d = new D()
d.Value
"""
|> typecheck
|> shouldFail
|> withSingleDiagnostic (Warning 20, Line 8, Col 5, Line 8, Col 12,
"The result of this expression has type 'int' and is implicitly ignored. Consider using 'ignore' to discard this value explicitly, e.g. 'expr |> ignore', or 'let' to bind the result to a name, e.g. 'let result = expr'.")
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. If adding more cases, a case with a computation expression could be useful. |
||
|
|
||
| [<Fact>] | ||
| let ``Warn If Possible Property Setter``() = | ||
| FSharp """ | ||
|
|
||
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.
@T-Gro Could you cherry-pick the comments rules from the other PR?