Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@doNotSubmit isn't valid on member-fields #56233

Open
matanlurey opened this issue Jul 13, 2024 · 5 comments
Open

@doNotSubmit isn't valid on member-fields #56233

matanlurey opened this issue Jul 13, 2024 · 5 comments
Labels
analyzer-pkg-meta Issues related to package:meta area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)

Comments

@matanlurey
Copy link
Contributor

import 'package:meta/meta.dart';

class A {
  @doNotSubmit
  var debugFlag = false;
}

I'd expect this to work, but the @Target we picked only allows getters, not fields. Workaround:

class A {
  @doNotSubmit
  bool get debugFlag => _debugFlag;
  final _debugFlag = false;
}
@dart-github-bot
Copy link
Collaborator

Summary: The @doNotSubmit annotation is not valid on member fields, only getters. This is because the @Target annotation for @doNotSubmit only allows it to be applied to getters, not fields. A workaround is to use a getter with a private field.

@dart-github-bot dart-github-bot added area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. type-bug Incorrect behavior (everything from a crash to more subtle misbehavior) labels Jul 13, 2024
@matanlurey
Copy link
Contributor Author

Similarly, it does not work on enum fields.

@devoncarew devoncarew added area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. and removed area-meta Cross-cutting, high-level issues (for tracking many other implementation issues, ...). labels Jul 13, 2024
@srawlins
Copy link
Member

Ah yeah we need to add TargetKind.enumValue and TargetKind.field.

@srawlins srawlins added P3 A lower priority bug or feature request analyzer-pkg-meta Issues related to package:meta labels Jul 15, 2024
@bwilkerson
Copy link
Member

I think we refer to them as constants elsewhere in the analyzer API's, so perhaps TargetKind.enumConstant?

@srawlins
Copy link
Member

TargetKind.enumValue is the existing... er... value/constant under TargetKind. The name was discussed in code review: https://dart-review.googlesource.com/c/sdk/+/360661

@lrhn lrhn removed the triage-automation See https://github.com/dart-lang/ecosystem/tree/main/pkgs/sdk_triage_bot. label Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
analyzer-pkg-meta Issues related to package:meta area-analyzer Use area-analyzer for Dart analyzer issues, including the analysis server and code completion. P3 A lower priority bug or feature request type-bug Incorrect behavior (everything from a crash to more subtle misbehavior)
Projects
None yet
Development

No branches or pull requests

6 participants