Fixed keyword triggers compiler error in implicit entrypoint
- Dominant language
- F#
- Stars
- 4.3k
- Forks
- 876
- Avg merge
- 4d 11h
- Merged PRs (30d)
- 131
Description
Using the `fixed` keyword in the implicit entrypoint triggers a compiler error. The same code in a function compiles just fine.
**Repro steps**
Provide the steps required to reproduce the problem:
1. Create new .NET 6 F# console app
2. Use the following code:
```fsharp
let inFunctionScope () =
let arr = [|1; 2; 3|]
use arrFixed = fixed arr // Works
()
let arr2 = [|1; 2; 3|]
use arrFixed2 = fixed arr2 // Compiler error
()
```
Repro ZIP file:
[FsharpBugFixedKeyword.zip](https://github.com/dotnet/fsharp/files/7781720/FsharpBugFixedKeyword.zip)
**Expected behavior**
No compiler error
**Actual behavior**
Compiler error:
```
Program.fs(7,5): error FS3207: Invalid use of 'fixed'. 'fixed' may only be used in a declaration of the form 'use x = fixed expr' where the expression is an array, the address of a field, the address of an array element or a string'
```
**Known workarounds**
Put fixed keyword into a function
**Related information**
* Operating system: Win11
* .NET Runtime kind (.NET Core, .NET Framework, Mono): .NET 6 SDK (6.0.100)
* Editing Tools (e.g. Visual Studio Version, Visual Studio): Rider (reproduced from command line too)
Contributor guide
Assessment
This issue has not been assessed yet.