Skip to content

[CP] Erase static interop type in static invocation #53579

Description

@srujzs

Commit(s) to merge

b25873f

Target

stable

Prepared changelist for beta/stable

https://dart-review.googlesource.com/c/sdk/+/327120

Issue Description

@anonymous @staticInterop classes using type parameters with factories crash on dart2js. An insufficient erasure led to a type mismatch in generated tear-offs that call these factories, which then triggered a crash. This is platform-agnostic but only materializes in dart2js.

What is the fix

The fix casts the invocation of the @staticInterop factory invocation to its erased type so that there isn't a type mismatch.

Why cherry-pick

This is an issue that is difficult to work around for users. Per my comment in #53479 (comment), users are forced to either move the factory to a static method, which won't be able to use class type parameters, use a top-level method, or get rid of class type parameters. All of these fixes will require breaking changes to users' packages to work around. Naturally, it's a breaking change again to go back to the old syntax once the issue is fixed. There is at least one existing package impacted by this: https://pub.dev/packages/record.

Risk

low

Issue link(s)

#53291 #53479 #53337

Extra Info

Note that the prepared changelist is slightly modified from the original CL. The only changes are in the test in that CL to support the fact that we didn't allow type parameters in extension members of @staticInterop classes (hence the Object? instead of T and U).

Metadata

Metadata

Labels

area-web-jsIssues related to JavaScript support for Dart Web, including DDC, dart2js, and JS interop.cherry-pick-approvedLabel for approved cherrypick requestcherry-pick-reviewIssue that need cherry pick triage to approvemerge-to-stableweb-dart2jsweb-js-interopIssues that impact all js interop

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions