dotnet / dotnet/fsharp

Nested modules defined in the wrong parent module when preceded by a string interpolution (multi line) surrounded with parentheses

Open
#18,416 2 comments 0 reactions 0 assignees View on GitHub
Area-Compiler-Syntax Bug Impact-Medium
Dominant language
F#
Stars
4.3k
Forks
876
Avg merge
4d 11h
Merged PRs (30d)
131

Description

Hello,

**Repro steps**

```fs
namespace SomethingTests.CG.Codecs

module Something =
module Versioned =
module DiscriminatedUnion =

module Version1 =
let foo () =
(function
| unknown ->
$"Hello:
- CaseA")

module Version2 =

let foo () =
failwith "Not implemented"

module Test =

let a = Something.Versioned.DiscriminatedUnion.Version1.foo
// Fails but should be valid
let b = Something.Versioned.DiscriminatedUnion.Version2.foo
// Valid but should fail
let c = Something.Versioned.Version2.foo
```

**Expected behavior**

The version of code using `Something.Versioned.DiscriminatedUnion.Version2.foo` should world.

**Actual behavior**

`Something.Versioned.DiscriminatedUnion.Version2.foo` is considered invalid when `Something.Versioned.Version2.foo` is valid

**Known workarounds**

1. Remove the parentheses around the `function` declaration (not possible in actual code)
2. Indent the line `- CaseA")` of one level ` - CaseA")` but this change the string value
3. Force place the closing parenthesis to be below at least the `module Version1 =` indentation
4. Don't use string interpolation and replace with string concatenation

```fs
module Version1 =
let foo () =
(function
| unknown ->
$"Hello:
- CaseA"
)
```

**Related information**

Could be related to https://github.com/dotnet/fsharp/issues/14394

Provide any related information (optional):

* Operating system: **Windows_NT**
* Arch: **x64**
* VSCode: **1.98.2**
* Ionide: **7.25.6**
* Runtime: **netcore**
* Dotnet version: **9.0.201**

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.