Skip to content

Using super with __index-based inheritance returns nil #1537

Description

@coDiesIrae

__TS__DescriptorGet uses rawget, which ignores __index, therefore returning nil when trying to access fields or methods of base class

For example, in dota_ts_adapter:

setmetatable(BaseAbility.prototype, {
  __index: CDOTA_Ability_Lua ?? C_DOTA_Ability_Lua,
});

Then, extending BaseAbility and calling method on super

class SuperAbility extends BaseAbility {
    GetBehavior() {
        const res = super.GetBehavior();
        // ...
    }
}

Produces the following lua code:

local res = __TS__DescriptorGet(self, BaseAbility.prototype, "GetBehavior")(self)

Which causes attempt to call a nil value error in runtime

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