Skip to content

Support for @checked on fields #27363

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

Closed
scheglov opened this issue Sep 15, 2016 · 10 comments
Closed

Support for @checked on fields #27363

scheglov opened this issue Sep 15, 2016 · 10 comments
Assignees
Labels
legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug

Comments

@scheglov
Copy link
Contributor

import 'package:meta/meta.dart';

class A {
  get foo => '';
  set foo(_) {}
}

class B extends A {
  @checked
  int foo;
}

Currently this code reports an error ERROR: Invalid override. The type of B.foo= ((int) → void) is not a subtype of A.foo= ((dynamic) → void). ([analyzer] bin/test.dart:10).

But if I encapsulate the field, then it works fine.

import 'package:meta/meta.dart';

class A {
  get foo => '';
  set foo(_) {}
}

class B extends A {
  int _foo;

  int get foo => _foo;

  void set foo(@checked int foo) {
    _foo = foo;
  }
}

Can / should we make it work similarly for the field case?

@scheglov
Copy link
Contributor Author

@keertip

@jmesserly
Copy link

Great question! -- @leafpetersen thoughts?

@bwilkerson bwilkerson added P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug labels Sep 16, 2016
@leafpetersen
Copy link
Member

This sounds good to me.

@leafpetersen
Copy link
Member

@sethladd

@jmesserly jmesserly self-assigned this Sep 17, 2016
@sethladd
Copy link
Contributor

Related to #25578

@jmesserly
Copy link

@leafpetersen
Copy link
Member

If this doesn't already, we may want to consider making this imply @virtual. There's kind of no point otherwise, and I'm not sure there's any benefit in requiring both annotations.

@jmesserly
Copy link

jmesserly commented Sep 22, 2016

@leafpetersen - here's a possible counter example?

abstract class BaseView {
  List<View> get children { ... }
  set children(List<View> views) { ... }
}
// intended to be sealed
class MyAppView extends BaseView {
  @checked List<MyChildView> children = [];
}

edit: add setter & extends :)

@jmesserly
Copy link

I'd hit send too fast, updated above example.

@leafpetersen
Copy link
Member

Ah good point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
legacy-area-analyzer Use area-devexp instead. P2 A bug or feature request we're likely to work on type-enhancement A request for a change that isn't a bug
Projects
None yet
Development

No branches or pull requests

5 participants