core icon indicating copy to clipboard operation
core copied to clipboard

Analyzer gives error on enum usage

Open V0d01ey opened this issue 7 years ago • 1 comments

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 avatar Sep 24 '18 07:09 V0d01ey

@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).

Jand42 avatar Oct 02 '18 08:10 Jand42