Skip to content

Compiler: direct super overwrites a receiver bound while evaluating its arguments #3513

Open

Description

@nickna

If a lexical super() call binds a derived constructor's receiver while the arguments of a direct super() are being evaluated, the direct call must still construct its parent. It must then throw a guest ReferenceError and keep the first receiver. The compiled path overwrites the receiver and runs its child fields again.

let runs = 0;
let parents = 0;
const C = class extends class { constructor(value) { parents++; } } {
    value = ++runs;
    constructor() {
        let inner;
        const initialize = () => inner = super(2);
        try { super(initialize()); }
        catch (error) { console.log(error instanceof ReferenceError); }
        console.log(this === inner);
    }
};
const value = new C();
console.log(value.value, runs, parents);

Node v22.23.2 prints:

true
true
1 1 2

The clean SharpTS baseline cabb41636 (CLI SHA256 5335B14C2A96172D0372D8FCDD75264741EB8A0B19C0273737C3BBF2967D3ACE) passes saved-IL verification and prints:

false
2 2 2

Compile and run with:

dotnet SharpTS.dll --no-tsconfig --compile probe.js -o probe.dll --verify
dotnet probe.dll

Found when verifying a review finding on #3510. This reduction uses only ordinary nongeneric user classes, and the second constructor attempt starts before either call has bound the receiver. Closed #2568 covers a second direct call starting after the receiver is already bound. Closed #3477 covers transporting elements through a single lexical call.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions