data_class icon indicating copy to clipboard operation
data_class copied to clipboard

fix: Dart Macros `declareInType` Incompatibility with Sealed Classes in Dart 3

Open manishgautammg3994 opened this issue 1 year ago • 0 comments

Issue Description

In Dart 3, there is an issue with Dart macros when applied to sealed classes. The macros incorrectly add the abstract keyword to the generated code, resulting in a compilation error.

Example

@Equatable() // considering the usage of the data_class package
sealed class CodePushState {
  const CodePushState();
}

Error

A 'sealed' class can't be marked 'abstract' because it's already implicitly abstract.
Try removing the 'abstract' keyword.
augment abstract sealed class CodePushState {

Steps to Reproduce:

  1. Define a sealed class as per Dart 3.
  2. Apply a Dart macro (using the data_class package) to the sealed class.
  3. Observe the generated Augment code , which incorrectly includes the abstract keyword.

Reference:

This issue has also been reported in the Dart language repository. You can track the progress here: Dart Macros Cannot Handle Sealed Classes Correctly (Dart 3) dart-lang/sdk#56525.

manishgautammg3994 avatar Aug 20 '24 14:08 manishgautammg3994