dotnet / dotnet/fsharp

[<Literal>] references fail in recursive modules

Open
#6,338 4 comments 0 reactions 1 assignee Claimed by @dsyme View on GitHub
Area-Compiler-Checking Area-Compiler-Checking-NameResolution Bug Impact-Medium
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 22h
Merged PRs (30d)
144

Description

Values with `[]` defined in recursive modules can not be used in contexts where a `[]` is required.

The following examples compile fine:

```f#
module NonRecursive

let [] x = ""
let [] y = x
```

```f#
module NonRecursive

type MyAttribute(x: string) =
inherit System.Attribute()

let [] x = ""
let [] y = ""
```

```f#
module rec Recursive

let [] x = ""
let y = x // literal not required, works fine even in recursive module
```

```f#
module NonRecursive

let [] x = ""

module rec Recursive =

let [] y = x
```

The following examples do not compile:

```f#
module rec Recursive

let [] x = ""
let [] y = x
// ^ The value or constructor 'x' is not defined
// ^ This is not a valid constant expression or custom attribute value
```

```f#
module rec Recursive

type MyAttribute(x: string) =
inherit System.Attribute()

let [] x = ""
let [] y = ""
// ^ The value or constructor 'x' is not defined
// ^ This is not a valid constant expression or custom attribute value
```

```f#
module rec Recursive =

let [] x = ""

module NonRecursive =

let [] 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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.