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

Same file name across different folders fails the compilation with error FS0239 #2679

Closed
et1975 opened this issue Mar 22, 2017 · 17 comments
Closed
Labels
Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Milestone

Comments

@et1975
Copy link

et1975 commented Mar 22, 2017

"An implementation of the file or module '%s' has already been given"
coming from:
https://github.com/Microsoft/visualfsharp/blob/d2915e6ffa0d852cb3002199e66ef83bd2e8d1d0/src/fsharp/CompileOps.fs#L5221

File is not a module and perhaps the compiler should take into account the folder it is in.

Repro steps

Create a project and organize it using following folder structure:

/folder1/a.fs
/folder1/b.fs
/folder2/a.fs
/folder2/b.fs

This kind of organization is beneficial for modelling certain problems and having to maintain different file names is a burden.

Expected behavior

It should compile.

Actual behavior

Even if the modules/namespaces defined by these files are different the compilation will still fail with FS0239

Known workarounds

Rename the files.

Related information

  • Operating system: n/a
  • Branch: n/a
  • .NET Runtime, CoreCLR or Mono Version: Mono 4.8 (.NET4.6)
  • Editing Tools (e.g. Visual Studio Version): n/a
  • Links to F# RFCs or entries on https://github.com/fsharp/fslang-suggestions: none
  • Links to performance testing scripts: n/a
  • Indications of severity: Minor
@enricosada
Copy link
Contributor

should work.
time ago there was a bug in VF# (so VS extension) about folder with same name, but i fixed that.
it continue to be a problem if you do

folder1/a.fs
folder2/b.fs
folder1/c.fs
folder2/d.fs

becaue treeview cannot render it because need to repeat folder2 twice (but vf# show a message about that)

can you build from command line the project using /v:n attribute? so is possibile to see fsc arguments

@enricosada
Copy link
Contributor

enricosada commented Mar 22, 2017

I can repro.

e:\tempet\folder2\a.fs(3,1): error FS0239: An implementation of the file or module 'A' has already been given [e:\tempet\tempet.fsproj]
e:\tempet\folder2\b.fs(3,1): error FS0239: An implementation of the file or module 'B' has already been given [e:\tempet\tempet.fsproj]
Build FAILED.
e:\tempet\folder2\a.fs(3,1): error FS0239: An implementation of the file or module 'A' has already been given [e:\tempet\tempet.fsproj]
e:\tempet\folder2\b.fs(3,1): error FS0239: An implementation of the file or module 'B' has already been given [e:\tempet\tempet.fsproj]
    0 Warning(s)
    2 Error(s)

I added a repro with new fsproj, but is fsc who complains, i checked fsc args afaik are correct.

just unzip the repro

tempet.zip

dotnet restore
dotnet build -v n

fsc arguments are right

         ,,,
         E:\tempet\folder1\a.fs
         E:\tempet\folder1\b.fs
         E:\tempet\folder2\a.fs
         E:\tempet\folder2\b.fs

NOTE that modules are not called 'A' and 'B', but have a namespace and distinct module name inside /cc @KevinRansom

added a screenshot because now VSCode is amazing :D

image

@et1975
Copy link
Author

et1975 commented Mar 29, 2017

Thanks for a quick fix folks, where can I find the fixed release?
Apparently the problem is exacerbated by the new Fable project system, same file name in a referenced dependency project is causing this error as well!
/cc @alfonsogarciacaro

@vasily-kirichenko
Copy link
Contributor

@et1975 I've closed my fix PR because I cannot fix some tests.

@alfonsogarciacaro
Copy link
Contributor

This is going to be a huge pain point for Fable if not fixed. At the moment we are merging all files (from every project) into a single project because this is the only (or at least easiest) way to get the full AST and inline functions across projects. As this is also a problem for .NET F# projects, I think it makes sense fixing it here instead of trying to find a workaround in Fable.

@dsyme @forki I'm trying to continue @vasily-kirichenko PR in #2728, but I need some guidance as I don't know the F# compiler code base very well. Some questions:

forki added a commit to forki/visualfsharp that referenced this issue Apr 2, 2017
forki added a commit to forki/visualfsharp that referenced this issue Apr 3, 2017
dsyme pushed a commit that referenced this issue Apr 3, 2017
* Simplified repro for #2679

* Fix dedupe issue in visualfsharp

* fix test

* Deduplicate the deduplication code

* fix compile error
@daniellittledev
Copy link

This still seems to be affecting VS 15.5.4 (in some cases) and ionide (in all cases)

@haf
Copy link

haf commented Feb 24, 2018

This still happens in large projects while they are compiling in the background, in both VSCode and Rider.

screen shot 2018-02-24 at 10 06 33

@NullVoxPopuli
Copy link

I have this issue with VS 2017

@abelbraaksma
Copy link
Contributor

@dsyme, could you reopen this, please? And perhaps also the related PR, as @alfonsogarciacaro mentioned there, it appears the fix didn't solve the issue: fsharp/fsharp-compiler-docs#748.

@NullVoxPopuli
Copy link

I have a way to easily replicate this:

  • open: https://github.com/NullVoxPopuli/CryptoExchangeClient/tree/websocket-support in visual studio 2017 Community (on that specific branch)

  • click run (examples project)

  • notice build succeeds.

  • stop debugging

  • Open side-by-side

    • base_exchange/client/WebSocketClient.fs
    • exchanges/cobinhood/clients/WebSocketClient.fs
  • Click around in both files, adding spaces in each one, saving after each change.

  • After 30 seconds, the file that appears lower the compilation list exhibits the error.

  • Closing and Re-opening Visual Studio is the only way to get rid of the error reliably.

  • Building the project still succeeds.

@dsyme dsyme reopened this Apr 13, 2018
@dsyme
Copy link
Contributor

dsyme commented Apr 13, 2018

@NullVoxPopuli Thanks for the repro

@kspeakman
Copy link

kspeakman commented Mar 4, 2019

As to severity. This bug strongly discourages using folders for organization. The errors generated are disruptive enough to force a change in project organization / naming strategy.

P.S. #nowarn "239" does nothing to prevent the error from displaying.

@cartermp cartermp modified the milestones: 16.1, 16.2 Apr 23, 2019
@cartermp cartermp modified the milestones: 16.2, Backlog Apr 30, 2019
@kspeakman
Copy link

kspeakman commented May 22, 2019

This continues to bite me in VS 2017 and 2019. It also has a subtle display bug in the Solution Explorer when you have a subfolder named the same as another subfolder in a different path.

image

1 Have to prefix certain files to avoid the error. Actually, just tried it and cannot replicate the error so far in 15.9.12.
2 Have to name the folder itself differently to avoid the display bug.

On the right you can see what happens if I name both subfolders "Handlers". It forces the folder to be displayed at the top even though this is not the compile order. It cannot be moved with Move Down. All the files/modules within it are differently named from the other Handlers folder.

image

This is the compile order from the project file. It does not match the Solution Explorer display on the right.

@dsyme dsyme added the Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. label Aug 26, 2020
@dsyme dsyme added Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code. Area-Compiler-Checking Type checking, attributes and all aspects of logic checking and removed Impact-Low (Internal MS Team use only) Describes an issue with limited impact on existing code. Area-Compiler labels Mar 31, 2022
@vzarytovskii vzarytovskii moved this to Not Planned in F# Compiler and Tooling Jun 17, 2022
@vzarytovskii vzarytovskii reopened this Jan 4, 2024
@github-project-automation github-project-automation bot moved this from Done to In Progress in F# Compiler and Tooling Jan 4, 2024
@auduchinok
Copy link
Member

@edgarfgp Could this be a good topic for somebody to do in Amplifying F#, maybe? 🙂
It may cover some basics of project options well, doesn't seem too hard, and should fix a nasty issue.

@nojaf
Copy link
Contributor

nojaf commented Jan 16, 2024

Is this still a problem? Cannot reproduce that sample @enricosada made years ago.

@edgarfgp
Copy link
Contributor

@edgarfgp Could this be a good topic for somebody to do in Amplifying F#, maybe? 🙂 It may cover some basics of project options well, doesn't seem too hard, and should fix a nasty issue.

Thanks for suggesting this. Based on Florian comment and my own testing. It seems that is not longer reproducible. cc @vzarytovskii

@vzarytovskii
Copy link
Member

Thanks for testing things folks

@github-project-automation github-project-automation bot moved this from In Progress to Done in F# Compiler and Tooling Jan 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Compiler-Checking Type checking, attributes and all aspects of logic checking Bug Impact-Medium (Internal MS Team use only) Describes an issue with moderate impact on existing code.
Projects
Archived in project