Skip to content

[<Literal>] references fail in recursive modules #6338

@cmeeren

Description

@cmeeren

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 = x
module 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 module
module NonRecursive

let [<Literal>] x = ""

module rec Recursive =

    let [<Literal>] y = x

The 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 value
module 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 value
module 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 value

Known 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

Status

New

Relationships

None yet

Development

No branches or pull requests

Issue actions