Show [<Literal>] and constant value for IL fields in Go to Metadata#19922
Show [<Literal>] and constant value for IL fields in Go to Metadata#19922T-Gro wants to merge 7 commits into
Conversation
…11526) Adds a new MetadataAsTextILField module in tests/FSharp.Compiler.Service.Tests/Symbols.fs covering the rendering of IL literal (const) static fields via FSharpEntity.TryGetMetadataText(). Tests added: - Theory with 5 rows (Int32/Int64/Byte/SByte MaxValue/MinValue) asserting the rendered metadata contains [<Literal>] and "= <value>". - Fact for System.Char.MaxValue asserting [<Literal>] and "=" appear on the MaxValue line. - Negative Fact for System.Math.PI (initonly, non-literal) asserting it is NOT tagged [<Literal>] and has no "=". Current state (RED): total: 7, failed: 6, succeeded: 1 - 5 Theory rows + Char.MaxValue Fact fail with Assert.Contains() Failure: Sub-string not found because NicePrint.layoutILFieldInfo currently drops [<Literal>] and the literal value. - Math.PI passes (guards against regression of normal static val rendering). Sprint 02 will implement the fix in src/Compiler/Checking/NicePrint.fs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…-to-Metadata Note: Sprint 01 test assumptions were partially incorrect: - Math.PI is actually a literal const in IL (not initonly); replaced with System.String.Empty for the non-literal case. - The 'first line containing fieldName' finder matched doc-comment lines; narrowed to lines containing 'val <fieldName>:'. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
fantomas no-op (both touched files are in .fantomasignore); no .bsl baseline drift observed in targeted MetadataAsTextILField run (7/7 passed in 13s). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
❗ Release notes requiredYou can open this PR in browser to add release notes: open in github.dev
|
CI `check_release_notes` requires the entry to live in the VNEXT release-notes path (currently 11.0.100.md), not in the shipped 9.0.300.md release. Move the bullet, no behavior change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
T-Gro
left a comment
There was a problem hiding this comment.
🤖 This review was generated by AI (@expert-reviewer agent). Findings may contain inaccuracies — please verify independently.
Reviewed the IL literal field rendering change in NicePrint.fs and the accompanying tests. The core approach (append the init value and the [<Literal>] attribute, gated on finfo.LiteralValue.IsSome, reusing the existing layoutAttribs/layoutILFieldInit helpers) is sound and consistent with how F# literal vals are already printed. One substantive gap noted inline regarding string/null literal fields.
| let fieldL = staticL ^^ WordL.keywordVal ^^ (nameL |> addColonL) ^^ typL | ||
| let isLiteral = finfo.LiteralValue.IsSome | ||
| let fieldL = | ||
| if isLiteral then fieldL ^^ PrintIL.layoutILFieldInit finfo.LiteralValue |
There was a problem hiding this comment.
PrintIL.layoutILFieldInit (defined around line 439) only handles the Bool, Char, integer and float ILFieldInit cases; ILFieldInit.String and ILFieldInit.Null fall through to _ -> None, which renders = (* value unavailable *).
Because this PR now appends [<Literal>] and the init for every literal IL field (isLiteral = finfo.LiteralValue.IsSome), a const string field (very common across the BCL, e.g. System.Net.Mime.MediaTypeNames) or a null-literal field will now render as e.g.
[<Literal>]
static val Foo: string = (* value unavailable *)
That is both a regression over the previous clean static val Foo: string and misleading, since the value is in fact known.
Suggested fix: handle ILFieldInit.String s (emit the quoted/escaped string literal) and ILFieldInit.Null (emit null) in layoutILFieldInit, and add a string-literal case to the new tests in Symbols.fs, which currently cover only numeric and Char types.
abonie
left a comment
There was a problem hiding this comment.
Agree with the comment about ILFieldInit.String/Null, otherwise PR looks good
Handle const string and null-literal IL fields in PrintIL.layoutILFieldInit so they emit the quoted string / null instead of '(* value unavailable *)'. The match is now exhaustive over ILFieldInit. Adds a string-literal test. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Addressed in 8b17938: PrintIL.layoutILFieldInit now handles ILFieldInit.String (emits the quoted string) and ILFieldInit.Null (emits |
Fixes #11526
IL literal (
const) fields such asSystem.Char.MaxValuenow render with[<Literal>]and their constant value in Go to Metadata, instead ofappearing as plain
static valdeclarations.