R24BREAKINGfunction

Constructor Changed

Flags when a class constructor's parameters change incompatibly. All 'new ClassName()' instantiation sites will fail.


Applies to

TypeScriptPythonGoJavaRust

Why it matters

Constructor changes affect every instantiation site. In large codebases, a class may be instantiated in dozens of files — factories, tests, dependency injection containers, and handler files.

Example

Before
// database.ts
export class Database {
  constructor(connectionString: string) {
    this.connect(connectionString);
  }
}

// caller
const db = new Database("postgres://localhost/app");
After (new required param in constructor)
// database.ts (BREAKING)
export class Database {
  constructor(connectionString: string, pool: ConnectionPool) {
    this.pool = pool;
    this.connect(connectionString);
  }
}

// caller — NOW BROKEN
const db = new Database("postgres://localhost/app");
// Missing required argument: pool

What you see in the terminal

$ npx dg check

  [BREAKING] Database (signature_change)
  src/database.ts:3
  Constructor signature for 'Database' changed incompatibly. Downstream consumers calling 'new Database()' will encounter compilation errors.

How detection works

The classifier checks if the function is a constructor (via the isConstructor flag), then applies the same parameter removal and required addition heuristics used by R01 and R03 specifically for constructors.

Real-world scenario

A database class adds a connection pool parameter to its constructor for resource management. Every `new Database()` call across the codebase needs to provide a pool instance.

Edge cases

  • Only fires for constructor functions (isConstructor flag must be set)
  • Adding an optional constructor parameter is not caught — that's the safe R05 path