Skip to content
This repository was archived by the owner on Nov 20, 2024. It is now read-only.

allow overriding abstract fields in NNBD #2285

Merged
merged 2 commits into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/src/rules/overridden_fields.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ class _Visitor extends SimpleAstVisitor<void> {

node.fields.variables.forEach((VariableDeclaration variable) {
final field = _getOverriddenMember(variable.declaredElement);
if (field != null) {
if (field != null && !field.isAbstract) {
rule.reportLint(variable.name);
}
});
Expand Down
195 changes: 195 additions & 0 deletions test/rules/experiments/nnbd/rules/overridden_fields.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: year

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've been preserving the years for copies of existing tests. Happy to rethink though?

// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// test w/ `pub run test -N overridden_fields`

class Base {
Object field = 'lorem';

Object something = 'change';
}

class Bad1 extends Base {
@override
final x = 1, field = 'ipsum'; // LINT
}

class Bad2 extends Base {
@override
Object something = 'done'; // LINT
}

class Bad3 extends Object with Base {
@override
Object something = 'done'; // LINT
}

class Ok extends Base {
Object newField; // OK

final Object newFinal = 'ignore'; // OK
}

class OK2 implements Base {
@override
Object something = 'done'; // OK

@override
Object field;
}

abstract class OK3 implements Base {
@override
Object something = 'done'; // OK
}

class GC11 extends Bad1 {
@override
Object something = 'done'; // LINT

Object gc33 = 'gc33';
}

abstract class GC12 implements Bad1 {
@override
Object something = 'done'; // OK
}

class GC13 extends Object with Bad1 {
@override
Object something = 'done'; // OK

@override
Object field = 'lint'; // LINT
}

abstract class GC21 extends GC11 {
@override
Object something = 'done'; // LINT
}

abstract class GC22 implements GC11 {
@override
Object something = 'done'; // OK
}

class GC23 extends Object with GC13 {
@override
Object something = 'done'; // LINT

@override
Object field = 'lint'; // LINT
}

class GC23_2 extends GC13 {
@override
var x = 7; // LINT
}

abstract class GC31 extends GC13 {
@override
Object something = 'done'; // LINT
}

abstract class GC32 implements GC13 {
@override
Object something = 'done'; // OK
}

class GC33 extends GC21 with GC13 {
@override
Object something = 'done'; // LINT

@override
Object gc33 = 'yada'; // LINT
}

class GC33_2 extends GC33 {
@override
var x = 3; // LINT

@override
Object gc33 = 'yada'; // LINT
}

class Super1 {}

class Sub1 extends Super1 {
@override
int y;
}

class Super2 {
int x, y;
}

class Sub2 extends Super2 {
@override
int y; // LINT
}

class Super3 {
int x;
}

class Sub3 extends Super3 {
int x; // LINT
}

class A1 {
int f;
}

class B1 extends A1 {}

abstract class C1 implements A1 {}

class D1 extends B1 implements C1 {
@override
int f; // LINT
}

class A extends B {}
class B extends A {
int field;
}

class StaticsNo {
static int a;
}

class VerifyStatic extends StaticsNo {
static int a;
}

mixin M on A1 {
@override
int f; // LINT

int g; // OK
}

abstract class BB {
abstract String s;
}

class AA extends BB {
/// Overriding abstracts in NNBD is OK.
@override
String s; // OK
}

class AAA with BB {
@override
String s; // OK
}

abstract class BBB {
abstract final String s;
}

class AAA extends BBB {
@override
String s; // OK
}