From 2f471ded9a61b08299b6c5b63dc8ba6278107903 Mon Sep 17 00:00:00 2001 From: Alex Berezhnykh Date: Fri, 23 Sep 2022 21:47:37 +0300 Subject: [PATCH] Don't allow union case unnamed fields in xmldoc (#13914) * Don't allow union case unnamed fields in xmldoc * . * fix doc * fix * fix * fix --- src/Compiler/Checking/CheckDeclarations.fs | 6 ++++- src/FSharp.Core/prim-types.fs | 2 +- src/FSharp.Core/prim-types.fsi | 2 +- .../Language/XmlComments.fs | 26 ++++++++++++++++++- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/Compiler/Checking/CheckDeclarations.fs b/src/Compiler/Checking/CheckDeclarations.fs index 0e3b8a7973b..1081998708b 100644 --- a/src/Compiler/Checking/CheckDeclarations.fs +++ b/src/Compiler/Checking/CheckDeclarations.fs @@ -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 diff --git a/src/FSharp.Core/prim-types.fs b/src/FSharp.Core/prim-types.fs index 1178620d63b..eb92de29cba 100644 --- a/src/FSharp.Core/prim-types.fs +++ b/src/FSharp.Core/prim-types.fs @@ -3854,7 +3854,7 @@ namespace Microsoft.FSharp.Core [] 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")) diff --git a/src/FSharp.Core/prim-types.fsi b/src/FSharp.Core/prim-types.fsi index ccac892f8fc..e639f3cb85e 100644 --- a/src/FSharp.Core/prim-types.fsi +++ b/src/FSharp.Core/prim-types.fsi @@ -2441,7 +2441,7 @@ namespace Microsoft.FSharp.Core /// The input value. /// /// An option representing the value. - | ValueSome: 'T -> 'T voption + | ValueSome: Item:'T -> 'T voption /// Get the value of a 'ValueSome' option. An InvalidOperationException is raised if the option is 'ValueNone'. member Value: 'T diff --git a/tests/FSharp.Compiler.ComponentTests/Language/XmlComments.fs b/tests/FSharp.Compiler.ComponentTests/Language/XmlComments.fs index fc554d1fcc9..c0378ae4208 100644 --- a/tests/FSharp.Compiler.ComponentTests/Language/XmlComments.fs +++ b/tests/FSharp.Compiler.ComponentTests/Language/XmlComments.fs @@ -206,4 +206,28 @@ module M = |> ignoreWarnings |> compile |> shouldSucceed - |> withDiagnostics [ ] \ No newline at end of file + |> withDiagnostics [ ] + + [] + let ``Union field - unnamed 01`` () = + Fsx""" + type A = + /// A + /// Item + | A of int + """ + |> withXmlCommentChecking + |> compile + |> withDiagnostics [ Warning 3390, Line 3, Col 13, Line 4, Col 48, "This XML comment is invalid: unknown parameter 'Item'" ] + + [] + let ``Union field - unnamed 02`` () = + Fsx""" + type A = + /// A + /// a + | A of int * a: int + """ + |> withXmlCommentChecking + |> compile + |> withDiagnostics [ ]