Skip to content

Commit c89036e

Browse files
github-actions[bot]Repo AssistCopilotdsyme
authored
[Repo Assist] Fix #734: ReturnInfo.ReturnType is None for getter+setter properties (#1012)
* Fix #734: ReturnInfo.ReturnType is None for getter+setter properties For properties with both a getter and a setter, the CurriedParameterGroups from FCS reflects the getter's unit parameter as an empty list [[]]. The previous pattern matching code would fall through to the catch-all setter branch (which returns None), discarding the getter's return type. Adding | [ [] ], _, true -> [], Some retType as a more specific pattern before the catch-all setter case correctly returns the getter's return type for getter+setter (and setter-only-with-no-args) properties. Also adds a test type Test_Issue734 with GetterOnly, SetterOnly, and GetterAndSetter properties, and a test verifying ReturnInfo.ReturnType is Some for each. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci: trigger CI checks --------- Co-authored-by: Repo Assist <repo-assist@github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com> Co-authored-by: Don Syme <dsyme@users.noreply.github.com>
1 parent ce8a2d6 commit c89036e

4 files changed

Lines changed: 47 additions & 1 deletion

File tree

RELEASE_NOTES.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Add `{{fsdocs-logo-alt}}` substitution (configurable via `<FsDocsLogoAlt>` MSBuild property, defaults to `Logo`) for accessible alt text on the header logo image. [#626](https://github.com/fsprojects/FSharp.Formatting/issues/626)
88

99
### Fixed
10+
* Fix `ApiDocMember.Details.ReturnInfo.ReturnType` returning `None` for properties that have both a getter and a setter. [#734](https://github.com/fsprojects/FSharp.Formatting/issues/734)
1011
* Improve error message when a named code snippet is not found (e.g. `(*** include:name ***)` with undefined name now reports the missing name clearly). [#982](https://github.com/fsprojects/FSharp.Formatting/pull/982)
1112
* HTML-encode XML doc text nodes and unresolved `<see cref>` values to prevent HTML injection and fix broken output when docs contain characters like `<`, `>`, or backticks in generic type notation. [#748](https://github.com/fsprojects/FSharp.Formatting/issues/748)
1213
* Add uppercase output kind extension (e.g. `HTML`, `IPYNB`) to `ConditionalDefines` so that `#if HTML` and `(*** condition: HTML ***)` work alongside their lowercase variants. [#693](https://github.com/fsprojects/FSharp.Formatting/issues/693)

src/FSharp.Formatting.ApiDocs/GenerateModel.fs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1538,6 +1538,7 @@ module internal SymbolReader =
15381538
let argInfos, retType =
15391539
match argInfos, v.HasGetterMethod, v.HasSetterMethod with
15401540
| [ AllAndLast(args, last) ], _, true -> [ args ], Some last.Type
1541+
| [ [] ], _, true -> [], Some retType
15411542
| _, _, true -> argInfos, None
15421543
| [ [] ], true, _ -> [], Some retType
15431544
| _, _, _ -> argInfos, Some retType

tests/FSharp.ApiDocs.Tests/ApiDocsTests.fs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,12 +455,40 @@ let ``ApiDocs model generation works on two sample F# assemblies`` (_format: Out
455455
model.Collection.Namespaces.[0].Entities
456456
|> List.filter (fun c -> c.IsTypeDefinition)
457457
|> function
458-
| x -> x.Length |> shouldEqual 10
458+
| x -> x.Length |> shouldEqual 11
459459

460460
let assemblies = [ for t in model.Collection.Namespaces.[0].Entities -> t.Assembly.Name ]
461461

462462
assemblies |> List.distinct |> List.sort |> shouldEqual [ "FsLib1"; "FsLib2" ]
463463

464+
[<Test>]
465+
let ``ApiDocs ReturnInfo.ReturnType is Some for properties with setters (issue 734)`` () =
466+
let libraries = [ testBin </> "FsLib2.dll" ]
467+
let inputs = [ for lib in libraries -> ApiDocInput.FromFile(lib, mdcomments = true) ]
468+
469+
let model =
470+
ApiDocs.GenerateModel(inputs, collectionName = "FsLib", substitutions = substitutions, libDirs = [ testBin ])
471+
472+
let typeEntity =
473+
model.Collection.Namespaces.[0].Entities
474+
|> List.find (fun e -> e.Name = "Test_Issue734")
475+
476+
let members = typeEntity.AllMembers
477+
478+
let getReturnType name =
479+
members
480+
|> List.tryFind (fun m -> m.Name = name)
481+
|> Option.bind (fun m -> m.ReturnInfo.ReturnType)
482+
483+
// Getter-only: ReturnType should be Some string
484+
getReturnType "GetterOnly" |> Option.isSome |> shouldEqual true
485+
486+
// Getter+setter: ReturnType should be Some string
487+
getReturnType "GetterAndSetter" |> Option.isSome |> shouldEqual true
488+
489+
// Setter-only: ReturnType should be Some string (value type)
490+
getReturnType "SetterOnly" |> Option.isSome |> shouldEqual true
491+
464492
[<Test>]
465493
[<TestCaseSource("formats")>]
466494
let ``ApiDocs generates Go to GitHub source links`` (format: OutputFormat) =

tests/FSharp.ApiDocs.Tests/files/FsLib2/Library2.fs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,22 @@ module ``Space-Missing`` =
129129
type ``Implicit-Cast``(value: int) = class end
130130

131131

132+
/// Test type with setter-only and getter+setter properties (issue #734)
133+
type Test_Issue734() =
134+
let mutable _value = ""
135+
136+
/// Getter-only property
137+
member _.GetterOnly = "getter"
138+
139+
/// Setter-only property
140+
member _.SetterOnly
141+
with set (value: string) = _value <- value
142+
143+
/// Getter and setter property
144+
member _.GetterAndSetter
145+
with get () = _value
146+
and set (value: string) = _value <- value
147+
132148
module CommentExamples =
133149
/// <summary>this does the thing</summary>
134150
/// <example>this is an example

0 commit comments

Comments
 (0)