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

F# library won't compile due to "Global error 'not a named type' at ..." #923

Closed
stevehv opened this issue Mar 11, 2018 · 1 comment
Closed

Comments

@stevehv
Copy link

stevehv commented Mar 11, 2018

I have an existing project which I tried to create a WebSharper library from. I created a new WebSharper library from the Visual Studio template and put my code there. However, compilation fails with the error Global error 'not a named type' at ... (full error at bottom).

The error mesesage doesn't tell where the error is coming from, so I had to remove code file by file until I found one of the problematic parts (is there an easier way to do this?).

Minimal reproduction example (tested with WebSharper v.4.2.3.236):

  • Create new "WebSharper 4 Library" F# project in Visual Studio
  • Paste the following code to the project:
namespace V2

type V2<[<Measure>] 'u> =
    struct
        val x : float<'u>
        val y : float<'u>
        new (x, y) = {x=x; y=y}
    end

    static member (+) (a : V2<_>, b : V2<_>) = 
        V2 (a.x + b.x, a.y + b.y)

Note that there is no JavaScript annotation, so I would expect the code to compile even if WebSharper doesn't know how to generate JavaScript for this class. However, this piece of code breaks compilation and gives a very unhelpful error message.

There seem to be also other kind of cases which will cause this same error. However, it is very difficult to create minimal examples of these if I don't even know which file causes the error except by trial and error.

Full error message:

Error	FS9001	Global error 'not a named type' at    at <StartupCode$FSharp-Compiler-Service>.$Symbols.get_TypeDefinition@1892.Invoke(Unit unitVar0)
   at Microsoft.FSharp.Compiler.SourceCodeServices.Impl.protect[a](FSharpFunc`2 f)
   at WebSharper.Compiler.FSharp.CodeReader.SymbolReader.ReadTypeSt(Boolean markStaticTP, FSharpMap`2 tparams, FSharpType t)
   at Microsoft.FSharp.Collections.Internal.IEnumerator.map@74.DoMoveNext(b& )
   at Microsoft.FSharp.Collections.Internal.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext()
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at WebSharper.Compiler.FSharp.CodeReader.SymbolReader.ReadTypeSt(Boolean markStaticTP, FSharpMap`2 tparams, FSharpType t)
   at Microsoft.FSharp.Collections.Internal.IEnumerator.map@74.DoMoveNext(b& )
   at Microsoft.FSharp.Collections.Internal.IEnumerator.MapEnumerator`1.System-Collections-IEnumerator-MoveNext()
   at Microsoft.FSharp.Collections.SeqModule.ToList[T](IEnumerable`1 source)
   at WebSharper.Compiler.FSharp.CodeReader.SymbolReader.ReadTypeSt(Boolean markStaticTP, FSharpMap`2 tparams, FSharpType t)
   at WebSharper.Compiler.FSharp.CodeReader.SymbolReader.ReadType(FSharpMap`2 tparams, FSharpType t)
   at WebSharper.Compiler.FSharp.CodeReader.SymbolReader.ReadMember(FSharpMemberOrFunctionOrValue x)
   at WebSharper.Compiler.FSharp.ProjectReader.getAnnot@254(SymbolReader sr, FSharpEntity cls, TypeAnnotation annot, Dictionary`2 annotations, FSharpMemberOrFunctionOrValue x)
   at WebSharper.Compiler.FSharp.ProjectReader.transformClass(Lazy`1 sc, Compilation comp, ResolveFuncArgs ac, SymbolReader sr, Dictionary`2 classAnnots, TypeAnnotation parentAnnot, FSharpEntity cls, List`1 members)
   at WebSharper.Compiler.FSharp.ProjectReader.transformAssembly@1095-3.Invoke(FSharpImplementationFileContents file)
   at Microsoft.FSharp.Collections.SeqModule.Iterate[T](FSharpFunc`2 action, IEnumerable`1 source)
   at WebSharper.Compiler.FSharp.ProjectReader.transformAssembly(Compilation comp, String assemblyName, WsConfig config, FSharpCheckProjectResults checkResults)
   at WebSharper.Compiler.FSharp.WebSharperFSharpCompiler.Compile[a](Task`1 prevMeta, String[] argv, WsConfig config, String assemblyName)
   at WebSharper.FSharp.Program.Compile$cont@110-1(WsConfig config, String thisName, WebSharperFSharpCompiler compiler, Boolean isBundleOnly, FSharpList`1 paths, AssemblyResolver aR, Unit unitVar)
   at WebSharper.FSharp.Program.Compile$cont@61(WsConfig config, WarnSettings warnSettings, String thisName, Unit unitVar)
   at WebSharper.FSharp.Program.compileMain$cont@255(String[] argv, Unit unitVar)
   at WebSharper.FSharp.Program.main(String[] argv)	FUtil	FSC	1	Active
@Jand42 Jand42 added the bug label Mar 12, 2018
@Jand42
Copy link
Member

Jand42 commented Mar 12, 2018

Thanks for the report! The WebSharper compiler does look through non JavaScript-annotated types too, because there are some basic support for even non-annotated records/unions (translating them to plain objects).

So the problem is that the F# type reader of WS is not prepared to see a Measure generic parameter, which properly should be ignored (Measure is erased even in .NET runtime).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants