Skip to content

fix(compiler): check ctor param decorators (arity + unexpected) like di.ts - #551

Merged
Brooooooklyn merged 1 commit into
mainfrom
fix/issue-550-param-decorator-arity
Oct 6, 2026
Merged

Brooooooklyn merged 1 commit into
mainfrom
fix/issue-550-param-decorator-arity

Conversation

@Brooooooklyn

Copy link
Copy Markdown
Member

Summary

Adds param_decorator_errors in directive/decorator.rs, mirroring ngtsc's getConstructorDependencies (di.ts):

  • @Inject() / @Attribute() with anything but exactly one argument → Unexpected number of arguments to @Inject(). / @Attribute(). (DECORATOR_ARITY_WRONG)
  • Any other @angular/core decorator on a constructor parameter → Unexpected decorator {name} on parameter. (DECORATOR_UNEXPECTED)
  • Only core decorators count (import check, alias- and namespace-aware: dec.import.name semantics); foreign decorators and non-ctor params are ignored.

Wired into the class dispatch in component/transform.rs after decorator_io_errors, suppressed when an io/query error already fired — getConstructorDependencies runs last inside extractDirectiveMetadata, and upstream throws on first error. Applies to every DI-compiled class kind (@Component, @Directive, @Pipe, @NgModule, @Injectable), matching the handlers that all call getValidConstructorDependencies.

@Injectable() on a ctor param now reports Unexpected decorator Injectable on parameter. — the pre-existing test_class_metadata_lists_any_angular_core_decorator was updated to expect it (its own comment already acknowledged upstream rejects this shape).

Test plan

  • cargo test -p oxc_angular_compiler — 41 binaries green.
  • New tests: test_param_decorator_arity_is_diagnostic (7 cases incl. bare @Inject, aliases, @Attribute), test_param_decorator_checks_respect_import_and_kind (foreign decorators, core.Inject(), non-ctor params, undecorated classes).

Fixes #550

…di.ts

ngtsc's getConstructorDependencies rejects @Inject()/@Attribute() with
other than one argument (DECORATOR_ARITY_WRONG) and any other
@angular/core decorator on a ctor parameter (DECORATOR_UNEXPECTED),
for every class a DI handler compiles. Add param_decorator_errors,
reported after the io/query checks — getConstructorDependencies sits
last inside extractDirectiveMetadata.
@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@Brooooooklyn
Brooooooklyn merged commit caf70ad into main Oct 6, 2026
10 checks passed
@Brooooooklyn
Brooooooklyn deleted the fix/issue-550-param-decorator-arity branch October 6, 2026 15:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

@Inject() arity not checked (DECORATOR_ARITY_WRONG)

1 participant