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

dynamic cast operator !! lack of warnings during build! #1895

Closed
giulioungaretti opened this issue Sep 4, 2019 · 5 comments
Closed

dynamic cast operator !! lack of warnings during build! #1895

giulioungaretti opened this issue Sep 4, 2019 · 5 comments

Comments

@giulioungaretti
Copy link

Description

Following the docs here: https://fable.io/docs/communicate/js-from-fable.html#Plain-Old-JavaScript-Objects .

I was expecting the code below to raise warnings when building it!

Repro code

module App

open Fable.Core.JsInterop
open Fable.Import
open Fable.Core


type IMyInterface =
    abstract foo: string with get, set
    abstract bar: float with get, set
    abstract baz: int option with get, set

// Warning, "foo" must be a string
let x: IMyInterface = !!{| foo = 5; bar = 4.; baz = Some 0 |}

// Warning, "bar" field is missing
let y: IMyInterface = !!{| foo = "5"; bAr = 4.; baz = Some 0 |}

// Ok, "baz" can be missing because it's optional
let z: IMyInterface = !!{| foo = "5"; bar = 4. |}

let  print(x: IMyInterface) =
  Browser.Dom.console.error(x)

print(x)
print(y)
print(z)
Browser.Dom.console.log(y)
Browser.Dom.console.log(z)

Expected and actual results

Expected a warning, got nothing.

Related information

$ npm show fable-compiler version

  • 2.3.23

  • Win 10 enterprise Insiders

@SCullman
Copy link
Contributor

SCullman commented Sep 4, 2019

LOL, I expected even no warning, then I read the linked documentation.

@alfonsogarciacaro
Copy link
Member

I should have marked this feature as experimental ;)

It seems the F# compiler introduced some extra bindings to fix dotnet/fsharp#6487 so Fable wasn't reading the AST properly. It will be fixed in the next Fable release 👍

@giulioungaretti
Copy link
Author

@alfonsogarciacaro thank you for the quick answer!

@giulioungaretti
Copy link
Author

    type IMyInterface =
        abstract foo: string with get, set
        abstract bar: float with get, set
        abstract baz: int option with get, set

    type INoWarning =
        inherit IMyInterface
        abstract more : string with get, set
    // Warning, "more" is missing
    let p: INoWarning = !!{| foo = 5; bar = 4. |}
   // Warning, foo is the wrong type
    let r: INoWarning = !!{| more= ""; foo = 5; bar = 4. |}

    // Ok, all is fine!
    let q: INoWarning = !!{| more= ""; foo = "5"; bar = 4. |}

@alfonsogarciacaro I think I found an unexpected behavior with the code above!

The compiler only shows the first expected warning but not the second!
I am assuming it has to do with inheritance but I am not fully sure!

Let me know if I should open another issue :D

@alfonsogarciacaro
Copy link
Member

Yeah, I think we're not supporting interface inheritance in this feature yet. Ok, let's open again this issue and I'll have a look. Hopefully it's not too difficult to fix :)

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

No branches or pull requests

3 participants