WebSharper

This little example throws:

1
2
3
4
5
6
[<WebSharper.JavaScript>]
module test =

  type Type = Type with
    static member inline Member x = x
    member inline   this.Member x = x

with exception:

1
2
3
4
5
6
7
8
System.ArgumentException: An item with the same key has already been added.
at System.ThrowHelper.ThrowArgumentException(ExceptionResource resource)
at System.Collections.Generic.Dictionary`2.Insert(TKey key, TValue value, Boolean add)
at <StartupCode$WebSharper-Compiler>.$Compilation.resolveRemainingInstanceMembers@1229-1.Invoke(String n)
at <StartupCode$WebSharper-Compiler>.$Compilation.resolveRemainingInstanceMembers@1173(Compilation this, FSharpTypeFunc printerrf, Resolver r, Dictionary`2 remainingInstanceMembers, HashSet`1 resolved, Hashed`1 typ, ClassInfo cls, FSharpList`1 ms)
at WebSharper.Compiler.Compilation.Resolve()
at WebSharper.Compiler.FSharp.ProjectReader.transformAssembly(Compilation comp, String assemblyName, FSharpCheckProjectResults checkResults)
at WebSharper.Compiler.FSharp.WebSharperFSharpCompiler.Compile(Task`1 prevMeta, String[] argv, String path, String assemblyName)
  • JankoA

    Hi, thanks for the report!

    I found a bit strange that F# compiler allows this, but indeed, F# can resolve the uses correctly. I would still think this is bit of bad practice because it is an unresolvable ambiguity from C#.

    F# 4.1 has support for inplicit "Module" suffix for modules and types with the same name (we will release a WebSharper 4 version with full support for F#4.1/C#7 very soon), so this is one possible workaround:

    1
    2
    3
    4
    5
    
        type Type = Type with
            member inline this.Member x = x
        
        module Type =
            let inline Member x = x
  • github

    Thanks for the tip!