Fix wrong warning 20 range in sequential expressions (#5735)#19504
Draft
Fix wrong warning 20 range in sequential expressions (#5735)#19504
Conversation
Member
|
@copilot : Try again |
Copilot stopped work on behalf of
T-Gro due to an error
March 27, 2026 08:31
Member
|
@copilot : Try again. |
Copilot stopped work on behalf of
T-Gro due to an error
March 27, 2026 11:44
Member
|
@copilot Try again |
In TcStmt, use the range of the last expression in a sequential chain for warnings, so "expression is ignored" diagnostics point at the offending expression rather than the entire sequential body. Add regression tests for for-loops and while-loops with non-unit last expressions (int, string types). Add release notes. Agent-Logs-Url: https://github.com/dotnet/fsharp/sessions/e2b8a05e-e65e-484e-b039-cc8723adb177 Co-authored-by: abonie <20281641+abonie@users.noreply.github.com>
Contributor
Author
Fixed in 36f51b6. The root cause was that |
Copilot
AI
changed the title
[WIP] Copilot Request
Fix wrong warning 20 range in sequential expressions (#5735)
Mar 31, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Fixes the "expression is implicitly ignored" (warning 20) squiggle pointing at the wrong range when the last expression in a sequential block (e.g. inside
for,whileloops) is non-unit.Root Cause
In
TcStmt, the rangemwas set tosynExpr.Rangewhich, for a sequential expression like a loop body with multiple statements, covered the entire body. When the non-unit type warning was emitted, it used this overly broad range. Thebooltype case was already handled correctly byReportImplicitlyIgnoredBoolExpressionwhich walks the typed expression tree, but non-bool types (int, string, etc.) used the wrong range.Changes Made
src/Compiler/Checking/Expressions/CheckExpressions.fs— Added alastExprRangehelper that walks theSynExpr.Sequentialchain to find the range of the last expression, and used it inTcStmtinstead ofsynExpr.Range.tests/FSharp.Compiler.ComponentTests/ErrorMessages/WarnExpressionTests.fs— Added 4 regression tests coveringfor-in,for-to, andwhileloops with non-unit last expressions (int, string types).docs/release-notes/.FSharp.Compiler.Service/11.0.100.md— Added release note entry.Testing
Warn Expressiontests pass (12 existing + 4 new)CustomAttributestests unaffected🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.