Fable: Cannot have two module members with same name

Created on 23 Sep 2019  路  7Comments  路  Source: fable-compiler/Fable

Description

Compiling certain bits of F#+ with Fable returns a Cannot have two module members with same name error.

Repro code

I've managed to track down an instance of this problem and I've isolated it down to a few files in a separate repo.
The problem can be reproduced by cloning the repo and running the following commands:

  • npm install
  • npm run-script build

    Expected and actual results

The error returned is as follows:

/Users/.../github/FableModuleNames/MiniFSPlus/Collection.fs(1,1): error FABLE: Cannot have two module members with same name: Distinct1$$$Distinct1$$23936A2A
/Users/.../github/FableModuleNames/MiniFSPlus/Collection.fs(1,1): error FABLE: Cannot have two module members with same name: Distinct$$$Distinct$$23936A2A
/Users/.../github/FableModuleNames/MiniFSPlus/Collection.fs(1,1): error FABLE: Cannot have two module members with same name: Rev$$$Rev$$23936A2A
/Users/.../github/FableModuleNames/MiniFSPlus/Collection.fs(1,1): error FABLE: Cannot have two module members with same name: Sort$$$Sort$$23936A2A
/Users/.../github/FableModuleNames/MiniFSPlus/Collection.fs(1,1): error FABLE: Cannot have two module members with same name: Split$$$Split$$5FDAFE20
fable: Compilation failed at 2:26:17 PM (11.119 s)
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! @ build: fable-splitter MiniFSPlus -o build --commonjs
npm ERR! Exit status 1
npm ERR!
npm ERR! Failed at the @ build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR! /Users/.../.npm/_logs/2019-09-24T13_26_17_107Z-debug.log

Related information

  • Fable version: 2.3.25
  • Operating system: MacOS 10.14.6

More information I've found

I've managed to focus down into the 2 lines that cause the error:

type Distinct1 =
static member inline Distinct1 (x: ^Collection<'T> , []_impl: Default1) = (^Collection<'T> : (static member Distinct1 : _->_) x) : 'Collection<'T>
static member inline Distinct1 (_: ^t when ^t : null and ^t : struct, _mthd: Default1) = id //must

Somehow, removing any arguments from either lines solves the error.

Most helpful comment

Everything seems to work fine, thank you!

All 7 comments

Hmm, Fables uses a hash to distinguish overloaded members. Probably in this case the same hash is generated for the two members, as generics are hashed by argument index not by name (because the name of the generic can be different in signature and implementation files). Are Default and Default1 aliases of the same type? Maybe we could also add a flag to optional arguments in the hash, that could help in this case.

I think he did a typo, both should be Default1 as from https://github.com/jbotto94/FableModuleNames/blob/master/MiniFSPlus/Collection.fs#L28-L29

@jbotto94 Correct me If I'm worng.

@gusty is right. It is my typo. I am sorry.

I've fixed the small example that reproduces the error.

Thanks for checking! Hmm, then this is gonna be tricky because the two overloads are only different because of the generic constraints. I guess we'll have to code the constrains in the hash too somehow, although I'm not sure how to do it just yet :/

Thank you for solving this!

@jbotto94 I just published fable-compiler 2.4.3, can you please check if it fixes the problem? Thanks!

Everything seems to work fine, thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

alfonsogarciacaro picture alfonsogarciacaro  路  3Comments

forki picture forki  路  3Comments

et1975 picture et1975  路  3Comments

stkb picture stkb  路  3Comments

forki picture forki  路  3Comments