Skip to content

Commit 1891d44

Browse files
srawlinsCommit Queue
authored andcommitted
analyzer: mock SDK: correct declarations in core library
* The declared static type of `override` is `Object`. * All `@Since` annotations specifying versions < 2.12 are removed. * BigInt is abstract, so `compareTo` can be abstract. * BigInt.parse is external. * bool is not abstract, so it's methods need implementations. * DateTime implements `Comparable<DateTime>`. * pragma is final. * Exception is abstract. * `int.parse` has no `onError` parameter. * Sink is generic. * StackTrace is abstract. * Because String is abstract, it's methods do not need impls. * String.contains takes a Pattern, not a String. * Type is abstract. * UnsupportedError extends Error. * Uri is abstract. Change-Id: Iede9b47c621b1ce8cbbad79da4c69b8ada54e8ab Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450964 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Samuel Rawlins <[email protected]>
1 parent bdff483 commit 1891d44

File tree

2 files changed

+60
-64
lines changed

2 files changed

+60
-64
lines changed

pkg/analyzer/lib/src/test_utilities/mock_sdk.dart

Lines changed: 27 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -261,40 +261,36 @@ import "dart:_internal" as internal show Symbol;
261261
@Since("2.1")
262262
export 'dart:async' show Future, Stream;
263263
264-
const deprecated = const Deprecated("next release");
264+
const Deprecated deprecated = Deprecated("next release");
265265
266-
const override = const _Override();
266+
const Object override = _Override();
267267
268268
external bool identical(Object? a, Object? b);
269269
270270
void print(Object? object) {}
271271
272272
class ArgumentError extends Error {
273-
ArgumentError([message]);
273+
ArgumentError([dynamic message, @Since("2.14") String? name]);
274274
275-
@Since("2.1")
276-
static T checkNotNull<@Since("2.8") T>(T? argument, [String? name]) => argument!;
275+
static T checkNotNull<T>(T? argument, [String? name]) => argument!;
277276
}
278277
279278
abstract final class BigInt implements Comparable<BigInt> {
280-
int compareTo(BigInt other) => 0;
281-
static BigInt parse(String source, {int? radix}) => throw 0;
279+
int compareTo(BigInt other);
280+
external static BigInt parse(String source, {int? radix});
282281
}
283282
284-
abstract final class bool extends Object {
283+
final class bool {
285284
external const factory bool.fromEnvironment(String name,
286285
{bool defaultValue = false});
287286
288287
external const factory bool.hasEnvironment(String name);
289288
290-
@Since("2.1")
291-
bool operator &(bool other);
289+
bool operator &(bool other) => throw 0;
292290
293-
@Since("2.1")
294-
bool operator |(bool other);
291+
bool operator |(bool other) => throw 0;
295292
296-
@Since("2.1")
297-
bool operator ^(bool other);
293+
bool operator ^(bool other) => throw 0;
298294
}
299295
300296
abstract class Comparable<T> {
@@ -304,14 +300,15 @@ abstract class Comparable<T> {
304300
305301
typedef Comparator<T> = int Function(T a, T b);
306302
307-
class DateTime extends Object {
303+
class DateTime implements Comparable<DateTime> {
308304
external DateTime._now();
309305
DateTime.now() : this._now();
306+
external int compareTo(DateTime other);
310307
external bool isBefore(DateTime other);
311308
external int get millisecondsSinceEpoch;
312309
}
313310
314-
class Deprecated extends Object {
311+
class Deprecated {
315312
final String? message;
316313
final _DeprecationKind _kind;
317314
const Deprecated(this.message) : _kind = _DeprecationKind.use;
@@ -329,7 +326,7 @@ enum _DeprecationKind {
329326
use, implement, extend, subclass, instantiate, mixin, optional;
330327
}
331328
332-
class pragma {
329+
final class pragma {
333330
final String name;
334331
final Object? options;
335332
const pragma(this.name, [this.options]);
@@ -404,7 +401,7 @@ class Error {
404401
external StackTrace? get stackTrace;
405402
}
406403
407-
class Exception {
404+
abstract interface class Exception {
408405
factory Exception([var message]) {
409406
throw 0;
410407
}
@@ -437,8 +434,7 @@ abstract final class int extends num {
437434
String toString();
438435
int truncate();
439436
440-
external static int parse(String source,
441-
{int? radix, @deprecated int onError(String source)?});
437+
external static int parse(String source, {int? radix});
442438
443439
external static int? tryParse(String source, {int? radix});
444440
}
@@ -541,7 +537,7 @@ abstract class Map<K, V> {
541537
V? remove(Object? key);
542538
}
543539
544-
final class Null extends Object {
540+
final class Null {
545541
factory Null._uninstantiable() {
546542
throw 0;
547543
}
@@ -636,11 +632,11 @@ abstract class Set<E> implements Iterable<E> {
636632
throw '';
637633
}
638634
639-
abstract class Sink {
635+
abstract interface class Sink<T> {
640636
void close();
641637
}
642638
643-
class StackTrace {}
639+
abstract interface class StackTrace {}
644640
645641
abstract final class String implements Comparable<String>, Pattern {
646642
external factory String.fromCharCodes(Iterable<int> charCodes,
@@ -652,24 +648,24 @@ abstract final class String implements Comparable<String>, Pattern {
652648
{String defaultValue = ""});
653649
654650
List<int> get codeUnits;
655-
bool get isEmpty => false;
656-
bool get isNotEmpty => false;
657-
int get length => 0;
651+
bool get isEmpty;
652+
bool get isNotEmpty;
653+
int get length;
658654
659655
bool operator ==(Object other);
660656
String operator [](int index);
661657
String operator +(String other);
662658
String operator *(int times);
663659
664660
int codeUnitAt(int index);
665-
bool contains(String other, [int startIndex = 0]);
661+
bool contains(Pattern other, [int startIndex = 0]);
666662
int indexOf(Pattern pattern, [int start = 0]);
667663
int lastIndexOf(Pattern pattern, [int? start]);
668664
bool startsWith(Pattern pattern, [int index = 0]);
669665
List<String> split(Pattern pattern);
670666
String splitMapJoin(Pattern pattern,
671667
{String Function(Match)? onMatch, String Function(String)? onNonMatch});
672-
String substring(int startIndex, [int? endIndex]);
668+
String substring(int start, [int? end]);
673669
String toLowerCase();
674670
String toUpperCase();
675671
}
@@ -684,15 +680,15 @@ class Symbol {
684680
const factory Symbol(String name) = internal.Symbol;
685681
}
686682
687-
class Type {}
683+
abstract interface class Type {}
688684
689685
class TypeError extends Error {}
690686
691-
class UnsupportedError {
687+
class UnsupportedError extends Error {
692688
UnsupportedError(String message);
693689
}
694690
695-
class Uri {
691+
abstract interface class Uri {
696692
factory Uri({
697693
String? scheme,
698694
String? userInfo,

pkg/linter/test/rules/avoid_type_to_string_test.dart

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -99,110 +99,110 @@ void foo(String Function() p) {}
9999
);
100100
}
101101

102-
test_typeExtendingType_withToStringOverride() async {
102+
test_typeImplementsType_withToStringOverride() async {
103103
await assertNoDiagnostics(r'''
104104
mixin M {
105105
@override
106106
String toString() => '';
107107
}
108-
class Type2 extends Type with M {
108+
class Type2 with M implements Type {
109109
String get x => toString();
110110
}
111111
''');
112112
}
113113

114-
test_typeThatExtendsType() async {
114+
test_typeThatExtendsTypeThatImplementsType() async {
115+
await assertDiagnostics(
116+
r'''
117+
var x = Type3().toString();
118+
class Type2 implements Type {}
119+
class Type3 extends Type2 {}
120+
''',
121+
[lint(16, 8)],
122+
);
123+
}
124+
125+
test_typeThatImplementsType() async {
115126
await assertDiagnostics(
116127
r'''
117128
var x = Type2().toString();
118-
class Type2 extends Type {}
129+
class Type2 implements Type {}
119130
''',
120131
[lint(16, 8)],
121132
);
122133
}
123134

124-
test_typeThatExtendsType_explicitThis() async {
135+
test_typeThatImplementsType_explicitThis() async {
125136
await assertDiagnostics(
126137
r'''
127-
class Type2 extends Type {
138+
class Type2 implements Type {
128139
late var x = this.toString();
129140
}
130141
''',
131-
[lint(47, 8)],
142+
[lint(50, 8)],
132143
);
133144
}
134145

135-
test_typeThatExtendsType_implicitThis() async {
146+
test_typeThatImplementsType_implicitThis() async {
136147
await assertDiagnostics(
137148
r'''
138-
class Type2 extends Type {
149+
class Type2 implements Type {
139150
late var x = toString();
140151
}
141152
''',
142-
[lint(42, 8)],
153+
[lint(45, 8)],
143154
);
144155
}
145156

146-
test_typeThatExtendsType_super() async {
157+
test_typeThatImplementsType_super() async {
147158
await assertDiagnostics(
148159
r'''
149-
class Type2 extends Type {
160+
class Type2 implements Type {
150161
late var x = super.toString();
151162
}
152163
''',
153-
[lint(48, 8)],
164+
[lint(51, 8)],
154165
);
155166
}
156167

157-
test_typeThatExtendsType_tearoff() async {
168+
test_typeThatImplementsType_tearoff() async {
158169
await assertDiagnostics(
159170
r'''
160-
class Type2 extends Type {}
171+
class Type2 implements Type {}
161172
void f(Type2 t) {
162173
foo(t.toString);
163174
}
164175
void foo(String Function() p) {}
165176
''',
166-
[lint(54, 8)],
177+
[lint(57, 8)],
167178
);
168179
}
169180

170-
test_typeThatExtendsType_tearoff_explicitThis() async {
181+
test_typeThatImplementsType_tearoff_explicitThis() async {
171182
await assertDiagnostics(
172183
r'''
173-
class Type2 extends Type {
184+
class Type2 implements Type {
174185
void f() {
175186
foo(this.toString);
176187
}
177188
void foo(String Function() p) {}
178189
}
179190
''',
180-
[lint(53, 8)],
191+
[lint(56, 8)],
181192
);
182193
}
183194

184-
test_typeThatExtendsType_tearoff_implicitThis() async {
195+
test_typeThatImplementsType_tearoff_implicitThis() async {
185196
await assertDiagnostics(
186197
r'''
187-
class Type2 extends Type {
198+
class Type2 implements Type {
188199
void f() {
189200
foo(toString);
190201
}
191202
void foo(String Function() p) {}
192203
}
193204
''',
194-
[lint(48, 8)],
195-
);
196-
}
197-
198-
test_typeThatExtendsTypeThatExtendsType() async {
199-
await assertDiagnostics(
200-
r'''
201-
var x = Type3().toString();
202-
class Type2 extends Type {}
203-
class Type3 extends Type2 {}
204-
''',
205-
[lint(16, 8)],
205+
[lint(51, 8)],
206206
);
207207
}
208208
}

0 commit comments

Comments
 (0)