Skip to content

Commit ea0077e

Browse files
Repo Assist (Copilot)Copilot
authored andcommitted
Fix crash on params array parameter types in API doc generation
When a C# method has a `params` array parameter (e.g. `params object[] args`), the array type is represented in FCS as an entity named `[]'1` whose `FullName` property throws because array types have no qualified name in the F# type system. Replace the single-expression type-name formatter in `getXmlDocSigForMember` with a small recursive helper (`formatParamType`) that: - handles generic parameters as before (via typeArgsMap), - detects array-type entities (`IsArrayType = true`) and builds the name as `<element-type-name><DisplayName>` (e.g. `System.Object[]`), and - falls back to `BasicQualifiedName` for types without a type definition. Also adds `ParamsMethod(params object[] args)` to the C# test fixture and a corresponding assertion in the existing csharp-support test to prevent regression. Fixes #439 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 8e3b463 commit ea0077e

4 files changed

Lines changed: 26 additions & 7 deletions

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* Strip `#if SYMBOL` / `#endif // SYMBOL` marker lines from `LiterateCode` source before syntax-highlighting so they do not appear in formatted output. [#693](https://github.com/fsprojects/FSharp.Formatting/issues/693)
1515
* Fix incorrect column ranges for inline spans (links, images, inline code) in the Markdown parser — spans and subsequent literals now report correct `StartColumn`/`EndColumn` values. [#744](https://github.com/fsprojects/FSharp.Formatting/issues/744)
1616
* Normalize `--projects` paths to absolute paths before passing to the project cracker, fixing failures when relative paths are supplied. [#793](https://github.com/fsprojects/FSharp.Formatting/issues/793)
17+
* Fix crash when generating API docs for C# methods with `params` array parameters — the array type `[]`1` now resolves correctly instead of throwing "does not have a qualified name". [#439](https://github.com/fsprojects/FSharp.Formatting/issues/439)
1718

1819
### Changed
1920
* Update FCS to 43.10.100. [#935](https://github.com/fsprojects/FSharp.Formatting/pull/966)

src/FSharp.Formatting.ApiDocs/GenerateModel.fs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -750,20 +750,30 @@ module internal CrossReferences =
750750
else
751751
""
752752

753+
let rec formatParamType (typ: FSharpType) =
754+
if typ.IsGenericParameter then
755+
typeArgsMap.[typ.GenericParameter.Name]
756+
elif typ.HasTypeDefinition then
757+
let td = typ.TypeDefinition
758+
759+
if td.IsArrayType then
760+
// Array types (e.g. params object[]) have no FullName in FCS.
761+
// Build it from the element type and the display-name suffix ("[]", "[,]" etc.)
762+
let elementTypeName = formatParamType typ.GenericArguments.[0]
763+
elementTypeName + td.DisplayName
764+
else
765+
td.FullName
766+
else
767+
typ.BasicQualifiedName
768+
753769
let paramList =
754770
if
755771
memb.CurriedParameterGroups.Count > 0
756772
&& memb.CurriedParameterGroups.[0].Count > 0
757773
then
758774
let head = memb.CurriedParameterGroups.[0]
759775

760-
let paramTypeList =
761-
head
762-
|> Seq.map (fun param ->
763-
if param.Type.IsGenericParameter then
764-
typeArgsMap.[param.Type.GenericParameter.Name]
765-
else
766-
param.Type.TypeDefinition.FullName)
776+
let paramTypeList = head |> Seq.map (fun param -> formatParamType param.Type)
767777

768778
"(" + System.String.Join(", ", paramTypeList) + ")"
769779
else

tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,9 @@ let ``ApiDocs test that csharp (publiconly) support works`` (format: OutputForma
810810
files.[(sprintf "csharpsupport-sampleclass.%s" format.Extension)]
811811
|> shouldContainText "My_Method"
812812

813+
files.[(sprintf "csharpsupport-sampleclass.%s" format.Extension)]
814+
|> shouldContainText "My_Params_Method"
815+
813816
files.[(sprintf "csharpsupport-sampleclass.%s" format.Extension)]
814817
|> shouldContainText "My_Property"
815818

tests/FSharp.ApiDocs.Tests/files/csharpSupport/SampleClass.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public SampleClass() { }
9393
/// </summary>
9494
public void Method() { }
9595

96+
/// <summary>
97+
/// My_Params_Method
98+
/// </summary>
99+
public void ParamsMethod(params object[] args) { }
100+
96101

97102
/// <summary>
98103
/// My_Property

0 commit comments

Comments
 (0)