Skip to content

add FS-1331 - Allow opens in type and expression scopes#810

Draft
ijklam wants to merge 7 commits intofsharp:mainfrom
ijklam:fs1131
Draft

add FS-1331 - Allow opens in type and expression scopes#810
ijklam wants to merge 7 commits intofsharp:mainfrom
ijklam:fs1131

Conversation

@ijklam
Copy link
Copy Markdown
Contributor

@ijklam ijklam commented Aug 3, 2025

Click “Files changed” → “⋯” → “View file” for the rendered RFC.

```fsharp
type C() =
do printfn "%d" Int32.MaxValue // <- Cannot find the `Int32` here
open System
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be considered an expressions-scoped open and NOT be valid in the member?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original suggestion doesn't mentioned this, but I think the contents opened in type should be valid in members.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, that makes sense. I was somehow thinking of an open inside the do body. Good that you added the extra example above for it.

Comment thread RFCs/FS-1331-Allow opens in type and expression scopes.md Outdated
Comment thread RFCs/FS-1331-Allow opens in type and expression scopes.md
Comment thread RFCs/FS-1331-Allow opens in type and expression scopes.md
Comment thread RFCs/FS-1331-Allow opens in type and expression scopes.md
This feature is only available in implementation files.

```fsharp
type C() =
Copy link
Copy Markdown
Member

@edgarfgp edgarfgp Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please add some samples about ?

type IFace =
    abstract F : int -> int
    open System
    member _.F _ = 3
        
{ new IFace with
    open System
    member _.F _ = 3
}

type C () =
    member _.F () = 3
    open System
    member _.F _ = 3
    open System
    interface IFace with
        open System
        member _.F _ = 3
       
type A =
    | A
    open System
    member _.F _ = 3
and B =
    | B
    open System
    member _.F _ = 3

type U =
    | A
    | B
    open System
    member _.F _ = 3

type R =
    open System
    { A : int }
    open System
    member _.F _ = 3

Copy link
Copy Markdown
Contributor Author

@ijklam ijklam Aug 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

opens in types can only be on the beginning of the type definition due to the complexity of making it can applied to member/val/interface ... with following the up-to-down order.
Object expressions and interface ... with cannot contain opens.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd be fine with the feature shipping, with none of the places @edgarfgp showcased, being supported; and giving more room for consideration about the samples and in-type-definition semantics.

Ideally, it could be used in a do block at type level, let bindings, and in members themselves (under the member implemention block, not in between in stuff like properties).

@Tarmil
Copy link
Copy Markdown
Contributor

Tarmil commented Aug 14, 2025

It looks like open type hasn't been considered. I think people will expect it to work, consistently with module-level open type, so the RFC should either include it, or explain why it doesn't.

Edit: actually it is present in the examples. Still, I think a mention in the text would be welcome.

@Martin521
Copy link
Copy Markdown
Contributor

Can a section "Changes to the F# spec" be added?

@T-Gro
Copy link
Copy Markdown
Contributor

T-Gro commented Aug 14, 2025

That makes sense. I will re-review once spec changes are added.

@T-Gro T-Gro marked this pull request as draft February 5, 2026 12:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants