oxc-project/oxc · error · OxcDiagnostic

Expected to call `super()`.

Error message

Expected to call `super()`.

What it means

Oxlint's port of ESLint constructor-super, missing_super_all variant (crates/oxc_linter/src/rules/eslint/constructor_super.rs:20). In a derived class, `this` cannot be used before `super()` runs, and instantiating a derived class whose constructor never calls super() throws a ReferenceError at runtime. The rule builds a control-flow graph (petgraph is imported in this file) and reports when no super() call is reachable from the constructor at all.

Source

Thrown at crates/oxc_linter/src/rules/eslint/constructor_super.rs:21

use rustc_hash::FxHashMap;

use oxc_ast::{AstKind, ast::*};
use oxc_cfg::{
    BlockNodeId, ControlFlowGraph, EdgeType,
    graph::{
        Direction,
        visit::{EdgeRef, neighbors_filtered_by_edge_weight},
    },
};
use oxc_diagnostics::OxcDiagnostic;
use oxc_macros::declare_oxc_lint;
use oxc_semantic::NodeId;
use oxc_span::{GetSpan, Span};

use crate::{AstNode, context::LintContext, rule::Rule};

fn missing_super_all(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Expected to call `super()`.")
        .with_help("Add a `super()` call to the constructor")
        .with_label(span)
}

fn missing_super_some(span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Lacked a call of `super()` in some code paths.")
        .with_help("Ensure `super()` is called in all code paths")
        .with_label(span)
}

fn duplicate_super(span: Span, first_super_span: Span) -> OxcDiagnostic {
    OxcDiagnostic::warn("Unexpected duplicate `super()`.")
        .with_help("Remove the duplicate `super()` call")
        .with_labels([
            span.primary_label("This path may call `super()` after it was already called."),
            first_super_span.label("`super()` was first called here."),
        ])
}

View on GitHub (pinned to e1e7af627c)

Solutions

  1. Add `super(...)` as the first statement of the derived constructor.
  2. Delete the constructor entirely if it does nothing custom — the implicit derived constructor forwards arguments and calls super().
  3. If the class intentionally extends null, do not call super() and do not touch `this` before manual initialization; otherwise point `extends` at a real class.

Example fix

// before
class Checkbox extends Input {
  constructor(props) {
    this.props = props; // ReferenceError at runtime
  }
}

// after
class Checkbox extends Input {
  constructor(props) {
    super(props);
  }
}
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json — keep this rule at error level so CI fails before the runtime does
{
  "rules": {
    "constructor-super": "error"
  }
}

Prevention

When it happens

Trigger: Any derived-class constructor whose body contains no super() call, e.g. `class B extends A { constructor() { this.x = 1; } }`; the diagnostic labels the constructor span.

Common situations: Refactoring a base class into a hierarchy and forgetting to add super() to new subclasses; constructor templates copied into derived classes; converting a plain class into a derived one.

Related errors


AI-assisted analysis of oxc-project/oxc@e1e7af627c (2026-08-20). Data as JSON: /api/errors/09b44c5a22fc25de. Report an issue: GitHub.