oxc-project/oxc · error · OxcDiagnostic

Unexpected duplicate `super()`.

Error message

Unexpected duplicate `super()`.

What it means

The duplicate_super variant of constructor-super (crates/oxc_linter/src/rules/eslint/constructor_super.rs:32). It reports a second super() call reachable after an earlier one on the same execution path; the engine itself rejects this with 'Super constructor may only be called once'. The diagnostic carries two labels: the duplicate site ('This path may call super() after it was already called.') and the span of the first call ('`super()` was first called here.').

Solutions

  1. Delete the later duplicate super() call.
  2. Keep exactly one super() as the first statement and pass all required arguments to it.

Example fix

// before
constructor() {
  super();
  if (cond) super();
}

// after
constructor() {
  super();
}
Defensive patterns

Strategy: validation

Validate before calling

// .oxlintrc.json
{
  "rules": {
    "constructor-super": "error"
  }
}

Prevention

When it happens

Trigger: super() appearing twice sequentially, or an unconditional super() followed by another reachable super() (e.g. inside an if or loop) in a derived-class constructor.

Common situations: Copy-paste merges of two constructors each containing super(); refactoring that moves super() into a branch while leaving the original call.

Related errors


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

Appendix: source

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

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."),
        ])
}

#[derive(Clone, Copy)]
struct SuperClassContext {
    span: Span,
    label: &'static str,
}

fn bad_super(span: Span, super_class_context: Option<SuperClassContext>) -> OxcDiagnostic {
    let mut labels = vec![span.primary_label("This `super()` call is invalid here.")];
    if let Some(context) = super_class_context {
        labels.push(context.span.label(context.label));
    }

View on GitHub (pinned to e1e7af627c)