This repository was archived by the owner on Nov 20, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 167
allow overriding abstract fields in NNBD #2285
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
195 changes: 195 additions & 0 deletions
195
test/rules/experiments/nnbd/rules/overridden_fields.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
// 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 | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: year
There was a problem hiding this comment.
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?