Warn when function type passed to interpolated string#19289
Warn when function type passed to interpolated string#19289
Conversation
- Extract duplicated warning block into warnForFunctionValuesInFillExprs local function - Restore accidentally deleted withStdOutContains assertion in FormattableString test
❗ Release notes required
|
|
I just realized that the warning would work best if we could already hint for suggesting fsharp/src/Compiler/Utilities/DependencyGraph.fs Lines 340 to 348 in 01bad01 |
|
Consider also applying the warning to delegate types too, which are effectively also functions. |
|
Should this warning also apply to |
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Conceptually, those would make sense as well - but they need more design when it comes to the = Not in this PR, but feel free to expand in the related suggestion for example 👍 . |
…interpolation # Conflicts: # docs/release-notes/.Language/preview.md # src/Compiler/FSComp.txt # src/Compiler/Facilities/LanguageFeatures.fs # src/Compiler/Facilities/LanguageFeatures.fsi # src/Compiler/xlf/FSComp.txt.cs.xlf # src/Compiler/xlf/FSComp.txt.de.xlf # src/Compiler/xlf/FSComp.txt.es.xlf # src/Compiler/xlf/FSComp.txt.fr.xlf # src/Compiler/xlf/FSComp.txt.it.xlf # src/Compiler/xlf/FSComp.txt.ja.xlf # src/Compiler/xlf/FSComp.txt.ko.xlf # src/Compiler/xlf/FSComp.txt.pl.xlf # src/Compiler/xlf/FSComp.txt.pt-BR.xlf # src/Compiler/xlf/FSComp.txt.ru.xlf # src/Compiler/xlf/FSComp.txt.tr.xlf # src/Compiler/xlf/FSComp.txt.zh-Hans.xlf # src/Compiler/xlf/FSComp.txt.zh-Hant.xlf # tests/FSharp.Compiler.ComponentTests/Language/InterpolatedStringsTests.fs
… directive The PR's warning code 3882 collided with main's lexHashElifMustBeFirst (3882) added by the #elif preprocessor directive feature. Renumbered to 3884 (next available). Updated all tests, release notes, and xlf files. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Warn when function value is used as interpolated string argument
Adds a new warning FS3882 when a function or delegate value is used as an interpolated string fill expression — a common mistake where the user likely forgot to apply the function to its arguments.
What's in this PR
LanguageFeature.WarnWhenFunctionValueUsedAsInterpolatedStringArg(F# 11.0)isFunTy) and delegate types (isDelegateTy) —System.Action,System.Func<>, etc.string-typed andFormattableString-typed interpolated strings#nowarn "3882"Bootstrap fixes
The new warning correctly caught real issues in the compiler's own codebase:
DependencyGraph.fs— was interpolating function parameters ({unpacker}) instead of meaningful stringsFSharpProjectSnapshot.fs— was interpolating a callback{f}where{fileName}was intendedTests
14 new tests covering: lambdas, partial application,
_.Membershorthand, named functions, delegates (Action/Func), multiple holes,FormattableString, format specifiers,#nowarnsuppression, and language version gating.