Skip to content
1 change: 1 addition & 0 deletions docs/release-notes/.FSharp.Compiler.Service/10.0.100.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Fix active pattern typechecking regression. ([Issue #18638](https://github.com/dotnet/fsharp/issues/18638), [PR #18642](https://github.com/dotnet/fsharp/pull/18642))
* Fix nullness warnings when casting non-nullable values to `IEquatable<T>` to match C# behavior. ([Issue #18759](https://github.com/dotnet/fsharp/issues/18759))
* Fix IsByRefLikeAttribute types being incorrectly suppressed in completion lists. Types like `Span<T>` and `ReadOnlySpan<T>` now appear correctly in IntelliSense.
* Fix Show XML doc for enum fields in external metadata ([Issue #17939](https://github.com/dotnet/fsharp/issues/17939#issuecomment-3137410105), [PR #18800](https://github.com/dotnet/fsharp/pull/18800))

### Changed
* Use `errorR` instead of `error` in `CheckDeclarations.fs` when possible. ([PR #18645](https://github.com/dotnet/fsharp/pull/18645))
Expand Down
32 changes: 23 additions & 9 deletions src/Compiler/Checking/NicePrint.fs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ module internal PrintUtilities =
let layoutXmlDocOfILFieldInfo (denv: DisplayEnv) (infoReader: InfoReader) (finfo: ILFieldInfo) restL =
if denv.showDocumentation then
GetXmlDocSigOfILFieldInfo infoReader Range.range0 finfo
|> layoutXmlDocFromSig denv infoReader true XmlDoc.Empty restL
|> layoutXmlDocFromSig denv infoReader true XmlDoc.Empty restL
else
restL

Expand Down Expand Up @@ -465,9 +465,11 @@ module PrintIL =
| None -> WordL.equals ^^ (comment "value unavailable")
| Some s -> WordL.equals ^^ wordL s

let layoutILEnumCase nm litVal =
let layoutILEnumCase nm litVal xmlDocOpt =
let nameL = ConvertLogicalNameToDisplayLayout (tagEnum >> wordL) nm
WordL.bar ^^ nameL ^^ layoutILFieldInit litVal
match xmlDocOpt with
| Some layout -> layout @@ (WordL.bar ^^ nameL ^^ layoutILFieldInit litVal)
| None -> WordL.bar ^^ nameL ^^ layoutILFieldInit litVal

module PrintTypes =
// Note: We need nice printing of constants in order to print literals and attributes
Expand Down Expand Up @@ -2108,9 +2110,8 @@ module TastDefinitionPrinting =

let ilFieldsL =
ilFields
|> List.map (fun x -> (true, x.IsStatic, x.FieldName, 0, 0), layoutILFieldInfo denv infoReader m x)
|> List.sortBy fst
|> List.map snd
|> List.sortBy (fun x -> x.IsStatic, x.FieldName)
|> List.map (fun x -> layoutILFieldInfo denv infoReader m x)

let staticVals =
if isRecdTy g ty then
Expand Down Expand Up @@ -2225,6 +2226,14 @@ module TastDefinitionPrinting =
else
(lhsL ^^ WordL.equals) -* rhsL

let tryGetFieldXml (layoutList: Layout list) idxOpt =
match idxOpt with
| Some i when i >= 0 && i < layoutList.Length ->
match layoutList[i] with
| Node (Node (_, right, _), _, _) -> Some right
| _ -> None
| _ -> None

let typeDeclL =

match repr with
Expand Down Expand Up @@ -2327,9 +2336,14 @@ module TastDefinitionPrinting =
|> addLhs

| TILObjectRepr _ when tycon.ILTyconRawMetadata.IsEnum ->
infoReader.GetILFieldInfosOfType (None, ad, m, ty)
|> List.filter (fun x -> x.FieldName <> "value__")
|> List.map (fun x -> PrintIL.layoutILEnumCase x.FieldName x.LiteralValue)
let ilFieldsSorted =
ilFields
|> List.sortBy (fun x -> x.IsStatic, x.FieldName)
infoReader.GetILFieldInfosOfType (None, ad, m, ty)
|> List.filter (fun (x: ILFieldInfo) -> x.FieldName <> "value__")
|> List.map (fun (x: ILFieldInfo) ->
let xmlDocOpt = List.tryFindIndex (fun (e: ILFieldInfo) -> e.FieldName = x.FieldName) ilFieldsSorted |> tryGetFieldXml ilFieldsL
PrintIL.layoutILEnumCase x.FieldName x.LiteralValue xmlDocOpt)
|> applyMaxMembers denv.maxMembers
|> aboveListL
|> addLhs
Expand Down
16 changes: 16 additions & 0 deletions tests/FSharp.Compiler.Service.Tests/Symbols.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1249,3 +1249,19 @@ module Delegates =

symbols["EventHandler"].IsDelegate |> shouldEqual true
symbols["Action"].IsDelegate |> shouldEqual true

module MetadataAsText =
[<Fact>]
let ``TryGetMetadataAsText returns metadata for external enum field`` () =
let _, checkResults = getParseAndCheckResults """
let test = System.DateTimeKind.Utc
"""
let symbolUse = checkResults |> findSymbolUseByName "DateTimeKind"
match symbolUse.Symbol with
| :? FSharpEntity as symbol ->
match symbol.TryGetMetadataText() with
| Some metadataText ->
metadataText.ToString() |> shouldContain "The time represented is UTC"
| None ->
failwith "Expected metadata text, got None"
| _ -> failwith "Expected FSharpEntity symbol"
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
[IL]: Error [StackUnexpected]: : FSharp.Compiler.CompilerConfig+TcConfig::.ctor([FSharp.Compiler.Service]FSharp.Compiler.CompilerConfig+TcConfigBuilder, bool)][offset 0x00000634][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : FSharp.Compiler.PatternMatchCompilation::isProblematicClause([FSharp.Compiler.Service]FSharp.Compiler.PatternMatchCompilation+MatchClause)][offset 0x00000065][found Byte] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : <StartupCode$FSharp-Compiler-Service>.$FSharp.Compiler.PatternMatchCompilation::.cctor()][offset 0x00000015][found Boolean] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : FSharp.Compiler.NicePrint+TastDefinitionPrinting+meths@2070-3::Invoke([FSharp.Compiler.Service]FSharp.Compiler.Infos+MethInfo)][offset 0x000000BE][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : FSharp.Compiler.NicePrint+TastDefinitionPrinting+meths@2072-3::Invoke([FSharp.Compiler.Service]FSharp.Compiler.Infos+MethInfo)][offset 0x000000BE][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : FSharp.Compiler.NicePrint+PrintUtilities::layoutXmlDoc([FSharp.Compiler.Service]FSharp.Compiler.TypedTreeOps+DisplayEnv, bool, [FSharp.Compiler.Service]FSharp.Compiler.Xml.XmlDoc, [FSharp.Compiler.Service]FSharp.Compiler.Text.Layout)][offset 0x00000033][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : FSharp.Compiler.TypeProviders::ValidateNamespaceName(string, [FSharp.Compiler.Service]FSharp.Compiler.Tainted`1<Microsoft.FSharp.Core.CompilerServices.ITypeProvider>, [FSharp.Compiler.Service]FSharp.Compiler.Text.Range, string)][offset 0x00000063][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : FSharp.Compiler.TypeProviders::ValidateExpectedName([FSharp.Compiler.Service]FSharp.Compiler.Text.Range, string[], string, [FSharp.Compiler.Service]FSharp.Compiler.Tainted`1<FSharp.Compiler.TypeProviders+ProvidedType>)][offset 0x000000AD][found Char] Unexpected type on the stack.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
[IL]: Error [StackUnexpected]: : FSharp.Compiler.IlxGen::HashRangeSorted([S.P.CoreLib]System.Collections.Generic.IDictionary`2<!!0,System.Tuple`2<int32,!!1>>)][offset 0x00000012][found ref '[FSharp.Compiler.Service]FSharp.Compiler.IlxGen+HashRangeSorted@1875<T1>'][expected ref '[FSharp.Core]Microsoft.FSharp.Core.FSharpFunc`2<System.Tuple`2<int32,T0>,T0>'] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : FSharp.Compiler.PatternMatchCompilation::isProblematicClause([FSharp.Compiler.Service]FSharp.Compiler.PatternMatchCompilation+MatchClause)][offset 0x00000040][found Byte] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : <StartupCode$FSharp-Compiler-Service>.$FSharp.Compiler.PatternMatchCompilation::.cctor()][offset 0x0000000B][found Boolean] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : FSharp.Compiler.NicePrint+TastDefinitionPrinting+meths@2070-3::Invoke([FSharp.Compiler.Service]FSharp.Compiler.Infos+MethInfo)][offset 0x000000B3][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : FSharp.Compiler.NicePrint+TastDefinitionPrinting+meths@2072-3::Invoke([FSharp.Compiler.Service]FSharp.Compiler.Infos+MethInfo)][offset 0x000000B3][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : FSharp.Compiler.NicePrint+PrintUtilities::layoutXmlDoc([FSharp.Compiler.Service]FSharp.Compiler.TypedTreeOps+DisplayEnv, bool, [FSharp.Compiler.Service]FSharp.Compiler.Xml.XmlDoc, [FSharp.Compiler.Service]FSharp.Compiler.Text.Layout)][offset 0x00000034][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : FSharp.Compiler.TypeProviders::ValidateNamespaceName(string, [FSharp.Compiler.Service]FSharp.Compiler.Tainted`1<Microsoft.FSharp.Core.CompilerServices.ITypeProvider>, [FSharp.Compiler.Service]FSharp.Compiler.Text.Range, string)][offset 0x00000074][found Char] Unexpected type on the stack.
[IL]: Error [StackUnexpected]: : FSharp.Compiler.TypeProviders::ValidateExpectedName([FSharp.Compiler.Service]FSharp.Compiler.Text.Range, string[], string, [FSharp.Compiler.Service]FSharp.Compiler.Tainted`1<FSharp.Compiler.TypeProviders+ProvidedType>)][offset 0x000000A8][found Char] Unexpected type on the stack.
Expand Down
Loading