dotnet-websharper / core

WebSharper - Full-stack, functional, reactive web apps and microservices in F# and C#
https://websharper.com
Apache License 2.0
594 stars 52 forks source link

Module-bound property use error #259

Open intellifactory-bb opened 9 years ago

intellifactory-bb commented 9 years ago

Lets say we have this alias

#!fsharp

let Canvas = HTML5.Tags.Canvas

then if use it like this

#!fsharp

(Canvas []).appendTo "entryPoint"

it will raise an error like this

Uncaught TypeError: Cannot read property 'GetEnumerator' of undefined

on the client side.


intellifactory-bb commented 9 years ago

Looks like the use of this property is correctly compiled, but the definition is compiled as-if a function.


Original comment by: Anton Tayanovskyy

intellifactory-bb commented 9 years ago

Upon further investigation, something incorrect happens with the [<Inline;JavaScript>] definition that is given on tag.Canvas.

If I manually expand the example, it works:

    let Canvas : seq<IPagelet> -> _ = HTML5.Tags.NewTag "Canvas"

Minimal repro not involving Canvas:


module Client =

    [<JavaScript>]
    let F x y = x + 1

    [<Inline; JavaScript>]
    let G y = F 0 y

    [<JavaScript>]
    let H = G

    [<JavaScript>]
    let Main () =
        JavaScript.Log(H 1)
        Div []

Original comment by: Anton Tayanovskyy

intellifactory-bb commented 9 years ago

Oops, actually still fails without Inline. Investigating.


Original comment by: Anton Tayanovskyy

intellifactory-bb commented 9 years ago

Let us see how the discussion goes on the F# repo: https://github.com/fsharp/fsharp/issues/321

We have some ad-hoc heuristics to recover from this situation, but apparently they still have holes. It would be very nice to simply fix the source of the error in the F# compiler. Or at least find a systematic strategy to recover.


Original comment by: Anton Tayanovskyy