Skip to content

New annotation request: @IntentToAddClassModifier.kFinal (and others) #54829

Open
@matanlurey

Description

@matanlurey

Starting at Dart 3.x+, we have class modifiers, yay!

I'd like a way to mark an intent to adopt a modifier in a future release, so that:

  1. The analyzer can issue diagnostics that a to-be-added modifier will become breaking.
  2. The user can ignore said issue (it's not a release blocker) and attend to it as they prioritize.

As a straw-man, I'd propose adding IntentToAddClassModifier to package:meta:

// meta.dart
import 'meta_meta.dart';

/// Annotation marking a class as soon-to-add the equivalent class modifier.
///
/// Tools, such as the analyzer, can provide feedback if
/// - the annotation is associated with anything other than a class
/// - the annotation is associated with a class `C` and the corresponding class modifier would be a static error 
@Target({TargetKind.classType})
enum IntentToAddClassModifier {
  kAbstract,
  kBase,
  kFinal,
  kInterface,
  kSealed,
  kMixin,
}

For example, I'd use it here: flutter/flutter#142937.

/cc @pq @srawlins (I wrote this here versus dart-lang/linter because of the need to re-use analyzer logic for modifiers).

Metadata

Metadata

Assignees

Labels

area-sdkUse area-sdk for general purpose SDK issues (packaging, distribution, …).

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions