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 👍 . |
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.