Skip to content

Context is not correctly inferred from indexed expression on this #959

@Perryvw

Description

@Perryvw

Example:

class Example {
    baz = 3;
    foo() {
        (this["bar"])()
    }

    bar() {
        return this.baz;
    }
}

const inst = new Example();
print(inst.foo())

Translates to (annotated with commentary):

Example = __TS__Class()
Example.name = "Example"
function Example.prototype.____constructor(self)
    self.baz = 3
end
function Example.prototype.foo(self)
    self.bar(nil) -- NOTE: This nil should actually be 'self'
end
function Example.prototype.bar(self)
    return self.baz -- Nil reference exception here
end

Playground link

Verified this in JS and it works fine there.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions