Skip to content

Commit

Permalink
core: generate this reg for implicit super call
Browse files Browse the repository at this point in the history
  • Loading branch information
cdragan committed Jun 25, 2022
1 parent 544c61f commit ada4537
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
2 changes: 1 addition & 1 deletion core/kos_compiler.c
Original file line number Diff line number Diff line change
Expand Up @@ -5740,7 +5740,7 @@ static int gen_function(KOS_COMP_UNIT *program,
assert(scope->num_args <= KOS_MAX_REGS);

/* Generate register for 'this' */
if (scope->uses_this) {
if (scope->uses_this || (needs_super_ctor && ! frame->uses_base_ctor)) {
TRY(gen_reg(program, &frame->this_reg));
++last_reg;
assert(frame->this_reg->reg == last_reg);
Expand Down
31 changes: 31 additions & 0 deletions tests/interpreter_tests/objects.kos
Original file line number Diff line number Diff line change
Expand Up @@ -1736,3 +1736,34 @@ do {
assert o.get(1) == void
assert o.get("x", 42) == 42
}

##############################################################################
# implicitly use `this` to invoke super
do {
class base
{
}

class derived extends base
{
constructor {
class inner extends base
{
constructor {
this.x = 42
}
}
throw inner()
}
}

var exc = void
try {
derived()
}
catch const e {
exc = e.value
}

assert exc.x == 42
}

0 comments on commit ada4537

Please sign in to comment.