core
core copied to clipboard
Analyzer gives error on enum usage
When using enum values in code for JS translation analyzer gives an error:
Type not found in JavaScript compilation: ClientServer10.Flags
[Flags]
public enum Flags
{
empty = 0x0,
notEmpty = 0x1
}
[JavaScript]
public static class Client
{
static public IControlBody Main()
{
if (Flags.empty == Flags.notEmpty) { } // <-- Analyzer error message: "Type not found in JavaScript compilation: ClientServer10.Flags"
<...>
}
}
Despite this error the project successfully builds.
@V0d01ey Thanks for the report, this is caused by #932. The WebSharper compilation currently does not gather information for enums/delegates by using language services (FCS/Roslyn) but with reflection. Compiler tool loads the referenced and current assemblies so that metaprogramming works (macro/generator types) and for validating RPC signatures. But the Roslyn analyzer cannot reflect on a changing current assembly.
#932 was never prioritized yet, but if you feel you would like to contribute, I can give additional guidance. (The trickiest part is probably reading F# union/record information via Roslyn, instead of using the FSharp.Reflection functions for keeping C#/F# compatibility, but eliminating relying on reflection. Or alternatively the possibility to use non-JavaScript-annotated F# types from C# can be dropped, it is a side case possibly never used).