From e7687c7b23d8c0d4adb21fb21cf3f8150cd74067 Mon Sep 17 00:00:00 2001 From: kerams Date: Fri, 26 Jun 2026 13:28:59 +0200 Subject: [PATCH 1/2] Improve implied argument names --- src/Compiler/Checking/MethodCalls.fs | 13 +++++- src/Compiler/FSComp.txt | 1 + src/Compiler/Facilities/LanguageFeatures.fs | 3 ++ src/Compiler/Facilities/LanguageFeatures.fsi | 1 + src/Compiler/xlf/FSComp.txt.cs.xlf | 5 +++ src/Compiler/xlf/FSComp.txt.de.xlf | 5 +++ src/Compiler/xlf/FSComp.txt.es.xlf | 5 +++ src/Compiler/xlf/FSComp.txt.fr.xlf | 5 +++ src/Compiler/xlf/FSComp.txt.it.xlf | 5 +++ src/Compiler/xlf/FSComp.txt.ja.xlf | 5 +++ src/Compiler/xlf/FSComp.txt.ko.xlf | 5 +++ src/Compiler/xlf/FSComp.txt.pl.xlf | 5 +++ src/Compiler/xlf/FSComp.txt.pt-BR.xlf | 5 +++ src/Compiler/xlf/FSComp.txt.ru.xlf | 5 +++ src/Compiler/xlf/FSComp.txt.tr.xlf | 5 +++ src/Compiler/xlf/FSComp.txt.zh-Hans.xlf | 5 +++ src/Compiler/xlf/FSComp.txt.zh-Hant.xlf | 5 +++ .../EmittedIL/ArgumentNames.fs | 45 +++++++++++++++++++ tests/FSharp.Test.Utilities/Compiler.fs | 3 ++ 19 files changed, 129 insertions(+), 2 deletions(-) diff --git a/src/Compiler/Checking/MethodCalls.fs b/src/Compiler/Checking/MethodCalls.fs index bfe806990db..156e52faee1 100644 --- a/src/Compiler/Checking/MethodCalls.fs +++ b/src/Compiler/Checking/MethodCalls.fs @@ -1355,15 +1355,24 @@ let BuildNewDelegateExpr (eventInfoOpt: EventInfo option, g, amap, delegateTy, d | _ -> None | _ -> None + let delInvokeArgNamesIfFeatureEnabled = + if g.langVersion.SupportsFeature LanguageFeature.ImprovedImpliedArgumentNamesPartTwo then + delInvokeMeth.GetParamNames() |> List.concat + else + [] + let delArgVals = delArgTys |> List.mapi (fun i argTy -> let argName = match delFuncArgNamesIfFeatureEnabled with | Some argNames -> argNames[i] - | None -> "delegateArg" + string i + | None -> + match List.tryItem i delInvokeArgNamesIfFeatureEnabled with + | Some (Some name) when name <> "" -> name + | _ -> "delegateArg" + string i - fst (mkCompGenLocal m argName argTy)) + fst (mkCompGenLocal m argName argTy)) let expr = let args = diff --git a/src/Compiler/FSComp.txt b/src/Compiler/FSComp.txt index d29b5d3dde7..97b2777b128 100644 --- a/src/Compiler/FSComp.txt +++ b/src/Compiler/FSComp.txt @@ -1822,3 +1822,4 @@ featurePreprocessorElif,"#elif preprocessor directive" 3889,tastNamespaceAndTypeWithSameNameInAssembly,"The namespace '%s' clashes with the type '%s'." featureExceptionFieldSerializationSupport,"emit GetObjectData and field-restoring deserialization constructor for exception types" featureErrorOnMissingSignatureAttribute,"error (rather than warning) when an enforced compiler-semantic attribute is present in the .fs but missing from the .fsi" +featureImprovedImpliedArgumentNamesPartTwo,"Improved implied argument names with partial application" diff --git a/src/Compiler/Facilities/LanguageFeatures.fs b/src/Compiler/Facilities/LanguageFeatures.fs index da4ef690311..7e035da7137 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fs +++ b/src/Compiler/Facilities/LanguageFeatures.fs @@ -110,6 +110,7 @@ type LanguageFeature = | PreprocessorElif | ExceptionFieldSerializationSupport | ErrorOnMissingSignatureAttribute + | ImprovedImpliedArgumentNamesPartTwo /// LanguageVersion management type LanguageVersion(versionText, ?disabledFeaturesArray: LanguageFeature array) = @@ -254,6 +255,7 @@ type LanguageVersion(versionText, ?disabledFeaturesArray: LanguageFeature array) LanguageFeature.WarnWhenFunctionValueUsedAsInterpolatedStringArg, languageVersion110 LanguageFeature.PreprocessorElif, languageVersion110 LanguageFeature.ExceptionFieldSerializationSupport, languageVersion110 + LanguageFeature.ImprovedImpliedArgumentNamesPartTwo, languageVersion110 // Difference between languageVersion110 and preview - 11.0 gets turned on automatically by picking a preview .NET 11 SDK // previewVersion is only when "preview" is specified explicitly in project files and users also need a preview SDK @@ -459,6 +461,7 @@ type LanguageVersion(versionText, ?disabledFeaturesArray: LanguageFeature array) | LanguageFeature.PreprocessorElif -> FSComp.SR.featurePreprocessorElif () | LanguageFeature.ExceptionFieldSerializationSupport -> FSComp.SR.featureExceptionFieldSerializationSupport () | LanguageFeature.ErrorOnMissingSignatureAttribute -> FSComp.SR.featureErrorOnMissingSignatureAttribute () + | LanguageFeature.ImprovedImpliedArgumentNamesPartTwo -> FSComp.SR.featureImprovedImpliedArgumentNamesPartTwo () /// Get a version string associated with the given feature. static member GetFeatureVersionString feature = diff --git a/src/Compiler/Facilities/LanguageFeatures.fsi b/src/Compiler/Facilities/LanguageFeatures.fsi index 5ba352191af..6234e422c69 100644 --- a/src/Compiler/Facilities/LanguageFeatures.fsi +++ b/src/Compiler/Facilities/LanguageFeatures.fsi @@ -101,6 +101,7 @@ type LanguageFeature = | PreprocessorElif | ExceptionFieldSerializationSupport | ErrorOnMissingSignatureAttribute + | ImprovedImpliedArgumentNamesPartTwo /// LanguageVersion management type LanguageVersion = diff --git a/src/Compiler/xlf/FSComp.txt.cs.xlf b/src/Compiler/xlf/FSComp.txt.cs.xlf index 3ea52c5b169..526fe0e8c86 100644 --- a/src/Compiler/xlf/FSComp.txt.cs.xlf +++ b/src/Compiler/xlf/FSComp.txt.cs.xlf @@ -457,6 +457,11 @@ Vylepšené názvy implikovaných argumentů + + Improved implied argument names with partial application + Improved implied argument names with partial application + + expr[idx] notation for indexing and slicing Notace expr[idx] pro indexování a vytváření řezů diff --git a/src/Compiler/xlf/FSComp.txt.de.xlf b/src/Compiler/xlf/FSComp.txt.de.xlf index f9fc62909ef..6369888a5db 100644 --- a/src/Compiler/xlf/FSComp.txt.de.xlf +++ b/src/Compiler/xlf/FSComp.txt.de.xlf @@ -457,6 +457,11 @@ Verbesserte implizite Argumentnamen + + Improved implied argument names with partial application + Improved implied argument names with partial application + + expr[idx] notation for indexing and slicing expr[idx]-Notation zum Indizieren und Aufteilen diff --git a/src/Compiler/xlf/FSComp.txt.es.xlf b/src/Compiler/xlf/FSComp.txt.es.xlf index eca7c688eed..26626973b69 100644 --- a/src/Compiler/xlf/FSComp.txt.es.xlf +++ b/src/Compiler/xlf/FSComp.txt.es.xlf @@ -457,6 +457,11 @@ Nombres de argumentos implícitos mejorados + + Improved implied argument names with partial application + Improved implied argument names with partial application + + expr[idx] notation for indexing and slicing Notación para indexación y segmentación expr[idx] diff --git a/src/Compiler/xlf/FSComp.txt.fr.xlf b/src/Compiler/xlf/FSComp.txt.fr.xlf index 0922cee5acd..6e4af6c4dc0 100644 --- a/src/Compiler/xlf/FSComp.txt.fr.xlf +++ b/src/Compiler/xlf/FSComp.txt.fr.xlf @@ -457,6 +457,11 @@ Noms d’arguments implicites améliorés + + Improved implied argument names with partial application + Improved implied argument names with partial application + + expr[idx] notation for indexing and slicing Notation expr[idx] pour l’indexation et le découpage diff --git a/src/Compiler/xlf/FSComp.txt.it.xlf b/src/Compiler/xlf/FSComp.txt.it.xlf index d39f0a33a85..5a5628c492f 100644 --- a/src/Compiler/xlf/FSComp.txt.it.xlf +++ b/src/Compiler/xlf/FSComp.txt.it.xlf @@ -457,6 +457,11 @@ Nomi di argomenti impliciti migliorati + + Improved implied argument names with partial application + Improved implied argument names with partial application + + expr[idx] notation for indexing and slicing Notazione expr[idx] per l'indicizzazione e il sezionamento diff --git a/src/Compiler/xlf/FSComp.txt.ja.xlf b/src/Compiler/xlf/FSComp.txt.ja.xlf index 6f4969e8148..606ce7c5c2a 100644 --- a/src/Compiler/xlf/FSComp.txt.ja.xlf +++ b/src/Compiler/xlf/FSComp.txt.ja.xlf @@ -457,6 +457,11 @@ 暗黙的な引数名の改善 + + Improved implied argument names with partial application + Improved implied argument names with partial application + + expr[idx] notation for indexing and slicing インデックス作成とスライス用の expr[idx] 表記 diff --git a/src/Compiler/xlf/FSComp.txt.ko.xlf b/src/Compiler/xlf/FSComp.txt.ko.xlf index fb488a6c240..cf8f99cecc4 100644 --- a/src/Compiler/xlf/FSComp.txt.ko.xlf +++ b/src/Compiler/xlf/FSComp.txt.ko.xlf @@ -457,6 +457,11 @@ 향상된 암시적 인수 이름 + + Improved implied argument names with partial application + Improved implied argument names with partial application + + expr[idx] notation for indexing and slicing 인덱싱 및 슬라이싱을 위한 expr[idx] 표기법 diff --git a/src/Compiler/xlf/FSComp.txt.pl.xlf b/src/Compiler/xlf/FSComp.txt.pl.xlf index 2720c59fc22..d282f0e1c17 100644 --- a/src/Compiler/xlf/FSComp.txt.pl.xlf +++ b/src/Compiler/xlf/FSComp.txt.pl.xlf @@ -457,6 +457,11 @@ Ulepszone nazwy dorozumianych argumentów + + Improved implied argument names with partial application + Improved implied argument names with partial application + + expr[idx] notation for indexing and slicing notacja wyrażenia expr[idx] do indeksowania i fragmentowania diff --git a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf index 8fc5566545f..2109691ae9f 100644 --- a/src/Compiler/xlf/FSComp.txt.pt-BR.xlf +++ b/src/Compiler/xlf/FSComp.txt.pt-BR.xlf @@ -457,6 +457,11 @@ Nomes de argumento implícitos aprimorados + + Improved implied argument names with partial application + Improved implied argument names with partial application + + expr[idx] notation for indexing and slicing notação expr[idx] para indexação e fatia diff --git a/src/Compiler/xlf/FSComp.txt.ru.xlf b/src/Compiler/xlf/FSComp.txt.ru.xlf index 16eb9766b81..d980693ea16 100644 --- a/src/Compiler/xlf/FSComp.txt.ru.xlf +++ b/src/Compiler/xlf/FSComp.txt.ru.xlf @@ -457,6 +457,11 @@ Улучшенные имена подразумеваемых аргументов + + Improved implied argument names with partial application + Improved implied argument names with partial application + + expr[idx] notation for indexing and slicing expr[idx] для индексации и среза diff --git a/src/Compiler/xlf/FSComp.txt.tr.xlf b/src/Compiler/xlf/FSComp.txt.tr.xlf index da5fd475a81..d2ea682250d 100644 --- a/src/Compiler/xlf/FSComp.txt.tr.xlf +++ b/src/Compiler/xlf/FSComp.txt.tr.xlf @@ -457,6 +457,11 @@ Geliştirilmiş örtük bağımsız değişken adları + + Improved implied argument names with partial application + Improved implied argument names with partial application + + expr[idx] notation for indexing and slicing Dizin oluşturma ve dilimleme için expr[idx] gösterimi diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf index c43aa519603..f4439e811c5 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hans.xlf @@ -457,6 +457,11 @@ 改进了默示的参数名称 + + Improved implied argument names with partial application + Improved implied argument names with partial application + + expr[idx] notation for indexing and slicing 用于索引和切片的 expr[idx] 表示法 diff --git a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf index d287b294184..f95fec79843 100644 --- a/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf +++ b/src/Compiler/xlf/FSComp.txt.zh-Hant.xlf @@ -457,6 +457,11 @@ 改良的隱含引數名稱 + + Improved implied argument names with partial application + Improved implied argument names with partial application + + expr[idx] notation for indexing and slicing 用於編製索引和分割的 expr[idx] 註釋 diff --git a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ArgumentNames.fs b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ArgumentNames.fs index 8b0aa7efb2c..69023c3b606 100644 --- a/tests/FSharp.Compiler.ComponentTests/EmittedIL/ArgumentNames.fs +++ b/tests/FSharp.Compiler.ComponentTests/EmittedIL/ArgumentNames.fs @@ -176,3 +176,48 @@ let test1 = System.Action<_, _>(add) int32) IL_0009: ret } """ ] + + [] + let ``Implied argument names are taken from delegate Invoke for a partial application``() = + FSharp """ +module ArgumentNames + +type Combine = delegate of first: int * second: int * third: int * fourth: int -> int + +[] +let f a b c d e g = a + b + c + d + e + g + +let test1 = Combine(f 1 2) + """ + |> withLangVersion11 + |> compile + |> shouldSucceed + |> verifyIL [" +.method assembly static int32 Invoke(int32 first, + int32 second, + int32 third, + int32 fourth) cil managed" ] + + [] + let ``Implied argument names are taken from delegate Invoke for a function composition``() = + FSharp """ +module ArgumentNames + +let test1 = System.Func(((+) 1) >> ((*) 2)) + """ + |> withLangVersion11 + |> compile + |> shouldSucceed + |> verifyIL ["Invoke(int32 arg) cil managed" ] + + [] + let ``Partial application delegate falls back to synthetic name before the feature``() = + FSharp """ +module ArgumentNames + +let test1 = System.Func((+) 1) + """ + |> withLangVersion10 + |> compile + |> shouldSucceed + |> verifyIL ["Invoke(int32 delegateArg0) cil managed" ] diff --git a/tests/FSharp.Test.Utilities/Compiler.fs b/tests/FSharp.Test.Utilities/Compiler.fs index 717590abccd..7632f7c4c93 100644 --- a/tests/FSharp.Test.Utilities/Compiler.fs +++ b/tests/FSharp.Test.Utilities/Compiler.fs @@ -644,6 +644,9 @@ $ code --diff {outFile} {expectedFile} let withLangVersion10 (cUnit: CompilationUnit) : CompilationUnit = withOptionsHelper [ "--langversion:10.0" ] "withLangVersion10 is only supported on F#" cUnit + + let withLangVersion11 (cUnit: CompilationUnit) : CompilationUnit = + withOptionsHelper [ "--langversion:11.0" ] "withLangVersion11 is only supported on F#" cUnit let withLangVersionPreview (cUnit: CompilationUnit) : CompilationUnit = withOptionsHelper [ "--langversion:preview" ] "withLangVersionPreview is only supported on F#" cUnit From 815852960ac4a2ab771d988d12e63a539a0d4eb5 Mon Sep 17 00:00:00 2001 From: kerams Date: Fri, 26 Jun 2026 13:38:27 +0200 Subject: [PATCH 2/2] Add release notes --- docs/release-notes/.FSharp.Compiler.Service/11.0.100.md | 1 + docs/release-notes/.Language/preview.md | 1 + 2 files changed, 2 insertions(+) diff --git a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md index ba843ca702c..5ebc10bc979 100644 --- a/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md +++ b/docs/release-notes/.FSharp.Compiler.Service/11.0.100.md @@ -106,6 +106,7 @@ * Debug: rework conditional erasure, fix stepping over literals ([PR #19897](https://github.com/dotnet/fsharp/pull/19897)) * Debug: fix if and match condition sequence points ([PR #19932](https://github.com/dotnet/fsharp/pull/19932)) * Checker: recover on checking language version ([PR ##19970](https://github.com/dotnet/fsharp/pull/19970)) +* Implied argument names for function-to-delegate coercions now fall back to the delegate's `Invoke` parameter names when the function has no recoverable names (e.g. a partial application like `System.Func((+) 1)`), instead of synthetic `delegateArg0`, `delegateArg1`, … names. ([PR #20001](https://github.com/dotnet/fsharp/pull/20001)) ### Improved diff --git a/docs/release-notes/.Language/preview.md b/docs/release-notes/.Language/preview.md index 90c1aa2faa6..2304ad7def6 100644 --- a/docs/release-notes/.Language/preview.md +++ b/docs/release-notes/.Language/preview.md @@ -3,6 +3,7 @@ * Warn (FS3884) when a function or delegate value is used as an interpolated string argument, since it will be formatted via `ToString` rather than being applied. ([PR #19289](https://github.com/dotnet/fsharp/pull/19289)) * Added `MethodOverloadsCache` language feature (preview) that caches overload resolution results for repeated method calls, significantly improving compilation performance. ([PR #19072](https://github.com/dotnet/fsharp/pull/19072)) * Added `ErrorOnMissingSignatureAttribute` preview language feature: makes FS3888 (compiler-semantic attribute on the `.fs` but not on the `.fsi`) an error instead of a warning. ([Issue #19560](https://github.com/dotnet/fsharp/issues/19560), [PR #19880](https://github.com/dotnet/fsharp/pull/19880)) +* Added `ImprovedImpliedArgumentNamesPartTwo` language feature: when a function with no recoverable parameter names is coerced to a delegate (e.g. a partial application like `System.Func((+) 1)`), the synthesized `Invoke` parameters take their names from the delegate's own `Invoke` signature instead of synthetic `delegateArg0`, `delegateArg1`, … names. ([PR #20001](https://github.com/dotnet/fsharp/pull/20001)) ### Fixed