Skip to content

Commit

Permalink
Don't allow union case unnamed fields in <param> xmldoc (#13914)
Browse files Browse the repository at this point in the history
* Don't allow union case unnamed fields in xmldoc

* .

* fix doc

* fix

* fix

* fix
  • Loading branch information
DedSec256 authored Sep 23, 2022
1 parent ff0f892 commit 2f471de
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/Compiler/Checking/CheckDeclarations.fs
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,11 @@ module TcRecdUnionAndEnumDeclarations =
error(Error(FSComp.SR.tcReturnTypesForUnionMustBeSameAsType(), m))
rfields, recordTy

let names = rfields |> List.map (fun f -> f.DisplayNameCore)
let names = rfields
|> Seq.filter (fun f -> not f.rfield_name_generated)
|> Seq.map (fun f -> f.DisplayNameCore)
|> Seq.toList

let xmlDoc = xmldoc.ToXmlDoc(true, Some names)
Construct.NewUnionCase id rfields recordTy attrs xmlDoc vis

Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Core/prim-types.fs
Original file line number Diff line number Diff line change
Expand Up @@ -3854,7 +3854,7 @@ namespace Microsoft.FSharp.Core
[<DebuggerDisplay("{DebugDisplay,nq}")>]
type ValueOption<'T> =
| ValueNone : 'T voption
| ValueSome : 'T -> 'T voption
| ValueSome : Item: 'T -> 'T voption

member x.Value = match x with ValueSome x -> x | ValueNone -> raise (new InvalidOperationException("ValueOption.Value"))

Expand Down
2 changes: 1 addition & 1 deletion src/FSharp.Core/prim-types.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -2441,7 +2441,7 @@ namespace Microsoft.FSharp.Core
/// <param name="Item">The input value.</param>
///
/// <returns>An option representing the value.</returns>
| ValueSome: 'T -> 'T voption
| ValueSome: Item:'T -> 'T voption

/// <summary>Get the value of a 'ValueSome' option. An InvalidOperationException is raised if the option is 'ValueNone'.</summary>
member Value: 'T
Expand Down
26 changes: 25 additions & 1 deletion tests/FSharp.Compiler.ComponentTests/Language/XmlComments.fs
Original file line number Diff line number Diff line change
Expand Up @@ -206,4 +206,28 @@ module M =
|> ignoreWarnings
|> compile
|> shouldSucceed
|> withDiagnostics [ ]
|> withDiagnostics [ ]

[<Fact>]
let ``Union field - unnamed 01`` () =
Fsx"""
type A =
/// <summary>A</summary>
/// <param name="Item">Item</param>
| A of int
"""
|> withXmlCommentChecking
|> compile
|> withDiagnostics [ Warning 3390, Line 3, Col 13, Line 4, Col 48, "This XML comment is invalid: unknown parameter 'Item'" ]

[<Fact>]
let ``Union field - unnamed 02`` () =
Fsx"""
type A =
/// <summary>A</summary>
/// <param name="a">a</param>
| A of int * a: int
"""
|> withXmlCommentChecking
|> compile
|> withDiagnostics [ ]

0 comments on commit 2f471de

Please sign in to comment.