Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't #load recursive namespaces into FSI #13516

Open
mciccottidmg opened this issue Jul 15, 2022 · 2 comments
Open

Can't #load recursive namespaces into FSI #13516

mciccottidmg opened this issue Jul 15, 2022 · 2 comments
Labels
Area-FSI Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone

Comments

@mciccottidmg
Copy link

A file with a recursive namespace reference can't be loaded in FSI. This is similar to #237.

It does compile as part of a project.

Steps to reproduce:

  1. Create a file named "test.fs" containing:
namespace rec FakeNamespaceName

module AType =

    type InnerType =
        member x.AMethod: FakeNamespaceName.AType2 = { AField = "test" }

type AType2 = { AField: string }
  1. Load the file in FSI:
#load "test.fs"

Expected behavior

The file is loaded into FSI.

Actual behavior

FSI gives this error:
test.fs(6,25): error FS0039: The namespace or module 'FakeNamespaceName' is not defined.

Known workarounds

  • Don't use recursive namespaces with FSI
  • Compile the code into an assembly and load that into FSI

Related information

Provide any related information (optional):

  • Microsoft (R) F# Interactive version 12.0.4.0 for F# 6.0
@KevinRansom
Copy link
Member

Interesting,

namespace isn't really valid in fsx files, use module rec SomeNamespace. I can't really explain the rationale though, and I had never noticed this behaviour before.

c:\kevinransom\fsharp>copy con foo.fsx
namespace HelloWorld
^Z
        1 file(s) copied.

c:\kevinransom\fsharp>dotnet fsi foo.fsx


foo.fsx(1,1): error FS0010: Unexpected keyword 'namespace' in interaction


c:\kevinransom\fsharp>

And also:

c:\kevinransom\fsharp>ue foo.fsx

c:\kevinransom\fsharp>fsc foo.fsx
Microsoft (R) F# Compiler version 12.0.4.0 for F# 6.0
Copyright (c) Microsoft Corporation. All Rights Reserved.

foo.fsx(1,21): warning FS0988: Main module of program is empty: nothing will happen when it is run

c:\kevinransom\fsharp>fsi foo.fsx


foo.fsx(1,1): error FS0010: Unexpected keyword 'namespace' in interaction

@mciccottidmg
Copy link
Author

Yeah, I wouldn't deliberately use namespaces in FSI. Its generated code though, so unfortunately I don't have a great alternative.

@vzarytovskii vzarytovskii moved this to Not Planned in F# Compiler and Tooling Sep 9, 2022
@vzarytovskii vzarytovskii added this to the Backlog milestone Sep 9, 2022
@dsyme dsyme added the Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. label Sep 21, 2022
@dsyme dsyme self-assigned this Sep 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-FSI Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Projects
Status: New
Development

No branches or pull requests

4 participants