Repository navigation
Open
Labels
Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingArea-Compiler-Checking-NameResolutionModule/type name collisions, open behavior, shadowing, global namespaceBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone
Description
Values with [<Literal>] defined in recursive modules can not be used in contexts where a [<Literal>] is required.
The following examples compile fine:
module NonRecursive
let [<Literal>] x = ""
let [<Literal>] y = xmodule NonRecursive
type MyAttribute(x: string) =
inherit System.Attribute()
let [<Literal>] x = ""
let [<MyAttribute(x)>] y = ""module rec Recursive
let [<Literal>] x = ""
let y = x // literal not required, works fine even in recursive modulemodule NonRecursive
let [<Literal>] x = ""
module rec Recursive =
let [<Literal>] y = xThe following examples do not compile:
module rec Recursive
let [<Literal>] x = ""
let [<Literal>] y = x
// ^ The value or constructor 'x' is not defined
// ^ This is not a valid constant expression or custom attribute valuemodule rec Recursive
type MyAttribute(x: string) =
inherit System.Attribute()
let [<Literal>] x = ""
let [<MyAttribute(x)>] y = ""
// ^ The value or constructor 'x' is not defined
// ^ This is not a valid constant expression or custom attribute valuemodule rec Recursive =
let [<Literal>] x = ""
module NonRecursive =
let [<Literal>] y = x
// ^ The value or constructor 'x' is not defined
// ^ This is not a valid constant expression or custom attribute valueKnown workarounds
Define literals outside recursive modules (may be infeasible in some cases).
Related information
May be related to #5227.
Metadata
Metadata
Assignees
Labels
Area-Compiler-CheckingType checking, attributes and all aspects of logic checkingArea-Compiler-Checking-NameResolutionModule/type name collisions, open behavior, shadowing, global namespaceBugImpact-Medium(Internal MS Team use only) Describes an issue with moderate impact on existing code.
Type
Projects
- StatusShow more project fieldsNew
Activity
TIHan commentedon Mar 25, 2019
The first two examples are a bug, but the last one is not correct to begin with and can be fixed by being qualified,
Recursive.x, or opening the module:or
These work fine.
cmeeren commentedon Mar 26, 2019
Sorry about the last one, got blinded by testing all aspects of the problem and made a brain fart... :)
dsyme commentedon Aug 26, 2020
See also
the discussion about this in the
nameofRFC discussionthis duplicate Recursive namespaces not working properly with type providers static parameters #5227
It's the same underlying issue in each case - literals values are not established in a separate phase
eiriktsarpalis commentedon Jul 1, 2021
I just bumped into this issue as well while trying to use xunit's
MemberDataAttributein conjuction withnameofin F#.github-actions commentedon Oct 3, 2026
🤖 This is an automated response from Repo Assist.
Verified that this still reproduces at repo HEAD
8512f9acbd9f757b75440b1ca6afe33fec321208(commit dated 2026-10-02, about 13 hours old at the start of this run).The freshly built FSI reports:
Minimal repro:
Compiling this with the Release compiler produces all three diagnostics at
x: FS0039 (xis not defined), FS0267 (not a valid constant expression or custom attribute value), and FS0837 (not a valid constant expression). The literal is still not established early enough for another literal in the same recursive module to reference it.Warning
Firewall blocked 1 domain
The following domain was blocked by the firewall during workflow execution:
southcentralus0.in.applicationinsights.azure.comSee Network Configuration for more information.
Add this agentic workflows to your repo
To install this agentic workflow, run