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

Inline Getters on abstract type producing assignment calls #656

Closed
Dessix opened this issue Jan 17, 2017 · 1 comment
Closed

Inline Getters on abstract type producing assignment calls #656

Dessix opened this issue Jan 17, 2017 · 1 comment

Comments

@Dessix
Copy link

Dessix commented Jan 17, 2017

Description

When providing inlined getter/setter combinations which refer to an Emit-attributed property on an abstract type, calls to the getter result in calls to the setter with either "null" or the setter variable name placed literally in the JS side, where no assignment should be taking place at all.

Repro code

[<AbstractClass>]
type TestClass =
    //Note the use of int IDs- this is an interface for having friendly names on an array- it will most certainly not have a "prop" attribute on the JS side.
    [<Emit("$0[$1]{{=$2}}")>] abstract Item: name: int -> obj with get, set
    member inline __.prop with get(): string = __.[0] :?> string and set(v: string): unit = __.[0] <- v

module TestClass =
    let inline create (prop: string): TestClass = [| box prop |] :> obj :?> TestClass

[<EntryPoint>]
let main args =
    let tc = TestClass.create "test"
    if (tc.prop <> "test") then failwith "Value not correctly accessed"
    0

Expected and actual results

Compiled Result:
See https://gist.github.com/Dessix/313635c089705dd11805b24e41fef845

Expected Result:
Getters should not produce assignments. Once #654 is resolved, non-inline getters should properly map to their concrete implementations rather than being treated as abstract.

Related information

  • fable-compiler version: 0.7.30
  • fable-core version: 0.7.22
  • Operating system: Win10x64
@alfonsogarciacaro
Copy link
Member

alfonsogarciacaro commented Jan 17, 2017

I'll check this but it looks as if an interface would be more appropriate in this case (an abstract class will be compiled as an actual ES6 class, see #654):

type TestClass =
    [<Emit("$0[0]{{=$1}}")>]
    abstract prop: string with get, set

module TestClass =
    let inline create (prop: string): TestClass = unbox [| prop |]

[<EntryPoint>]
let main args =
    let tc = TestClass.create "test"
    if (tc.prop <> "test") then failwith "Value not correctly accessed"
    0

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

2 participants