Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 439caba

Browse files
rmacnak-googlecommit-bot@chromium.org
authored andcommitted
[test] Changes to mirrors tests to make them more Dart 3 compatible.
These changes are not sufficient by themselves, but the subset that can still run in Dart 2. Bug: dart-lang/sdk#40045 Change-Id: Ie8f61fc9ee94b85329a701f97b5d3f91dbc1f889 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/132422 Commit-Queue: Ryan Macnak <rmacnak@google.com> Reviewed-by: Siva Annamalai <asiva@google.com> Reviewed-by: Ben Konyi <bkonyi@google.com>
1 parent ec28afc commit 439caba

File tree

93 files changed

+366
-327
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+366
-327
lines changed

tests/lib_2/mirrors/bad_argument_types_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void badClassStaticInvoke() {
8080
}
8181

8282
void badStaticInvoke() {
83-
final ClosureMirror im = reflect(foo);
83+
final im = reflect(foo) as ClosureMirror;
8484
Expect.throwsTypeError(() => im.apply(['Hello world!']));
8585
}
8686

@@ -124,7 +124,7 @@ void badGenericFactoryInvoke() {
124124
}
125125

126126
void badGenericStaticInvoke() {
127-
final ClosureMirror im = reflect(bar);
127+
final im = reflect(bar) as ClosureMirror;
128128
Expect.throwsTypeError(() => im.apply(['Hello world!']));
129129
}
130130

tests/lib_2/mirrors/basic_types_in_dart_core_test.dart

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,43 @@ import 'package:expect/expect.dart';
1010
main() {
1111
LibraryMirror dartcore = currentMirrorSystem().findLibrary(#dart.core);
1212
ClassMirror cm;
13+
TypeMirror tm;
1314

14-
cm = dartcore.declarations[#int];
15+
cm = dartcore.declarations[#int] as ClassMirror;
1516
Expect.equals(reflectClass(int), cm);
1617
Expect.equals(#int, cm.simpleName);
1718

18-
cm = dartcore.declarations[#double];
19+
cm = dartcore.declarations[#double] as ClassMirror;
1920
Expect.equals(reflectClass(double), cm);
2021
Expect.equals(#double, cm.simpleName);
2122

22-
cm = dartcore.declarations[#num];
23+
cm = dartcore.declarations[#num] as ClassMirror;
2324
Expect.equals(reflectClass(num), cm);
2425
Expect.equals(#num, cm.simpleName);
2526

26-
cm = dartcore.declarations[#bool];
27+
cm = dartcore.declarations[#bool] as ClassMirror;
2728
Expect.equals(reflectClass(bool), cm);
2829
Expect.equals(#bool, cm.simpleName);
2930

30-
cm = dartcore.declarations[#String];
31+
cm = dartcore.declarations[#String] as ClassMirror;
3132
Expect.equals(reflectClass(String), cm);
3233
Expect.equals(#String, cm.simpleName);
3334

34-
cm = dartcore.declarations[#List];
35+
cm = dartcore.declarations[#List] as ClassMirror;
3536
Expect.equals(reflectClass(List), cm);
3637
Expect.equals(#List, cm.simpleName);
3738

38-
cm = dartcore.declarations[#Null];
39+
cm = dartcore.declarations[#Null] as ClassMirror;
3940
Expect.equals(reflectClass(Null), cm);
4041
Expect.equals(#Null, cm.simpleName);
4142

42-
cm = dartcore.declarations[#Object];
43+
cm = dartcore.declarations[#Object] as ClassMirror;
4344
Expect.equals(reflectClass(Object), cm);
4445
Expect.equals(#Object, cm.simpleName);
4546

46-
cm = dartcore.declarations[#dynamic];
47-
Expect.isNull(cm);
47+
tm = dartcore.declarations[#dynamic] as TypeMirror;
48+
Expect.isNull(tm);
4849

49-
cm = dartcore.declarations[const Symbol('void')];
50-
Expect.isNull(cm);
50+
tm = dartcore.declarations[const Symbol('void')] as TypeMirror;
51+
Expect.isNull(tm);
5152
}

tests/lib_2/mirrors/class_mirror_location_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,12 @@ enum AnnotatedEnum { SALT, PEPPER }
3434
// any number of absolute paths.
3535
expectLocation(
3636
DeclarationMirror mirror, String uriSuffix, int line, int column) {
37-
Uri uri = mirror.location.sourceUri;
37+
final location = mirror.location;
38+
final uri = location.sourceUri;
3839
Expect.isTrue(
3940
uri.toString().endsWith(uriSuffix), "Expected suffix $uriSuffix in $uri");
40-
Expect.equals(line, mirror.location.line, "line");
41-
Expect.equals(column, mirror.location.column, "column");
41+
Expect.equals(line, location.line, "line");
42+
Expect.equals(column, location.column, "column");
4243
}
4344

4445
main() {

tests/lib_2/mirrors/class_mirror_type_variables_expect.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ void testA(Env env) {
4545

4646
TypeVariableMirror aT = a.typeVariables[0];
4747
TypeVariableMirror aS = a.typeVariables[1];
48-
ClassMirror aTBound = aT.upperBound;
49-
ClassMirror aSBound = aS.upperBound;
48+
ClassMirror aTBound = aT.upperBound as ClassMirror;
49+
ClassMirror aSBound = aS.upperBound as ClassMirror;
5050

5151
Expect.isTrue(aTBound.isOriginalDeclaration);
5252
Expect.isTrue(aSBound.isOriginalDeclaration);
@@ -64,8 +64,8 @@ void testBAndC(Env env) {
6464

6565
TypeVariableMirror bZ = b.typeVariables[0];
6666
TypeVariableMirror cZ = c.typeVariables[0];
67-
ClassMirror bZBound = bZ.upperBound;
68-
ClassMirror cZBound = cZ.upperBound;
67+
ClassMirror bZBound = bZ.upperBound as ClassMirror;
68+
ClassMirror cZBound = cZ.upperBound as ClassMirror;
6969

7070
Expect.isFalse(bZBound.isOriginalDeclaration);
7171
Expect.isFalse(cZBound.isOriginalDeclaration);
@@ -108,7 +108,7 @@ testD(Env env) {
108108
void testE(Env env) {
109109
ClassMirror e = env.getE();
110110
TypeVariableMirror eR = e.typeVariables.single;
111-
ClassMirror mapRAndHelperOfString = eR.upperBound;
111+
ClassMirror mapRAndHelperOfString = eR.upperBound as ClassMirror;
112112

113113
Expect.isFalse(mapRAndHelperOfString.isOriginalDeclaration);
114114
Expect.equals(eR, mapRAndHelperOfString.typeArguments.first);
@@ -119,8 +119,8 @@ void testE(Env env) {
119119
void testF(Env env) {
120120
ClassMirror f = env.getF();
121121
TypeVariableMirror fZ = f.typeVariables[0];
122-
ClassMirror fZBound = fZ.upperBound;
123-
ClassMirror fZBoundTypeArgument = fZBound.typeArguments.single;
122+
ClassMirror fZBound = fZ.upperBound as ClassMirror;
123+
ClassMirror fZBoundTypeArgument = fZBound.typeArguments.single as ClassMirror;
124124

125125
Expect.equals(1, f.typeVariables.length);
126126
Expect.isFalse(fZBound.isOriginalDeclaration);

tests/lib_2/mirrors/closurization_equivalence_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class C {
1313
}
1414

1515
main() {
16-
LibraryMirror thisLibrary = reflectClass(C).owner;
16+
LibraryMirror thisLibrary = reflectClass(C).owner as LibraryMirror;
1717
Expect.equals(thisLibrary.declarations[#topLevelMethod],
1818
(reflect(topLevelMethod) as ClosureMirror).function, "topLevel");
1919

tests/lib_2/mirrors/constructor_kinds_test.dart

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ main() {
4444
cm = reflectClass(ClassWithDefaultConstructor);
4545
mm = cm.declarations.values
4646
.where((d) => d is MethodMirror && d.isConstructor)
47-
.single;
47+
.single as MethodMirror;
4848
Expect.isTrue(mm.isConstructor);
4949
Expect.isTrue(mm.isGenerativeConstructor);
5050
Expect.isFalse(mm.isFactoryConstructor);
@@ -53,57 +53,57 @@ main() {
5353

5454
cm = reflectClass(Class);
5555

56-
mm = cm.declarations[#Class.generativeConstructor];
56+
mm = cm.declarations[#Class.generativeConstructor] as MethodMirror;
5757
Expect.isTrue(mm.isConstructor);
5858
Expect.isTrue(mm.isGenerativeConstructor);
5959
Expect.isFalse(mm.isFactoryConstructor);
6060
Expect.isFalse(mm.isRedirectingConstructor);
6161
Expect.isFalse(mm.isConstConstructor);
6262

63-
mm = cm.declarations[#Class.redirectingGenerativeConstructor];
63+
mm = cm.declarations[#Class.redirectingGenerativeConstructor] as MethodMirror;
6464
Expect.isTrue(mm.isConstructor);
6565
Expect.isTrue(mm.isGenerativeConstructor);
6666
Expect.isFalse(mm.isFactoryConstructor);
6767
Expect.isTrue(mm.isRedirectingConstructor);
6868
Expect.isFalse(mm.isConstConstructor);
6969

70-
mm = cm.declarations[#Class.factoryConstructor];
70+
mm = cm.declarations[#Class.factoryConstructor] as MethodMirror;
7171
Expect.isTrue(mm.isConstructor);
7272
Expect.isFalse(mm.isGenerativeConstructor);
7373
Expect.isTrue(mm.isFactoryConstructor);
7474
Expect.isFalse(mm.isRedirectingConstructor);
7575
Expect.isFalse(mm.isConstConstructor);
7676

77-
mm = cm.declarations[#Class.redirectingFactoryConstructor];
77+
mm = cm.declarations[#Class.redirectingFactoryConstructor] as MethodMirror;
7878
Expect.isTrue(mm.isConstructor);
7979
Expect.isFalse(mm.isGenerativeConstructor);
8080
Expect.isTrue(mm.isFactoryConstructor);
8181
Expect.isTrue(mm.isRedirectingConstructor);
8282
Expect.isFalse(mm.isConstConstructor);
8383

84-
mm = cm.declarations[#Class.constGenerativeConstructor];
84+
mm = cm.declarations[#Class.constGenerativeConstructor] as MethodMirror;
8585
Expect.isTrue(mm.isConstructor);
8686
Expect.isTrue(mm.isGenerativeConstructor);
8787
Expect.isFalse(mm.isFactoryConstructor);
8888
Expect.isFalse(mm.isRedirectingConstructor);
8989
Expect.isTrue(mm.isConstConstructor);
9090

91-
mm = cm.declarations[#Class.constRedirectingGenerativeConstructor];
91+
mm = cm.declarations[#Class.constRedirectingGenerativeConstructor] as MethodMirror;
9292
Expect.isTrue(mm.isConstructor);
9393
Expect.isTrue(mm.isGenerativeConstructor);
9494
Expect.isFalse(mm.isFactoryConstructor);
9595
Expect.isTrue(mm.isRedirectingConstructor);
9696
Expect.isTrue(mm.isConstConstructor);
9797

9898
// Not legal.
99-
// mm = cm.declarations[#Class.constFactoryConstructor];
99+
// mm = cm.declarations[#Class.constFactoryConstructor] as MethodMirror;
100100
// Expect.isTrue(mm.isConstructor);
101101
// Expect.isFalse(mm.isGenerativeConstructor);
102102
// Expect.isTrue(mm.isFactoryConstructor);
103103
// Expect.isFalse(mm.isRedirectingConstructor);
104104
// Expect.isTrue(mm.isConstConstructor);
105105

106-
mm = cm.declarations[#Class.constRedirectingFactoryConstructor];
106+
mm = cm.declarations[#Class.constRedirectingFactoryConstructor] as MethodMirror;
107107
Expect.isTrue(mm.isConstructor);
108108
Expect.isFalse(mm.isGenerativeConstructor);
109109
Expect.isTrue(mm.isFactoryConstructor);

tests/lib_2/mirrors/deferred_mirrors_metadata_lib.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ class H {
99

1010
class F {
1111
@H()
12-
int f;
12+
int f = 0;
1313
}
1414

1515
@C()
1616
class E {
1717
@D()
18-
var f;
18+
dynamic f;
1919
}
2020

2121
String foo() {

tests/lib_2/mirrors/deferred_mirrors_metatarget_lib.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ class A {
1616
}
1717

1818
String foo() {
19-
ClassMirror a = currentMirrorSystem().findLibrary(#lib).declarations[#A];
19+
final a =
20+
currentMirrorSystem().findLibrary(#lib).declarations[#A] as ClassMirror;
2021
return a.newInstance(Symbol.empty, []).invoke(#toString, []).reflectee;
2122
}

tests/lib_2/mirrors/equality_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ class BadEqualityHash {
2626
}
2727

2828
typedef bool Predicate(Object o);
29-
Predicate somePredicate;
29+
Predicate somePredicate = (Object o) => false;
3030

31-
checkEquality(List<Map> equivalenceClasses) {
31+
checkEquality(List<Map<String, Object>> equivalenceClasses) {
3232
for (var equivalenceClass in equivalenceClasses) {
3333
equivalenceClass.forEach((name, member) {
3434
equivalenceClass.forEach((otherName, otherMember) {
@@ -61,7 +61,7 @@ main() {
6161
var badEqualityHash1 = new BadEqualityHash();
6262
var badEqualityHash2 = new BadEqualityHash();
6363

64-
checkEquality([
64+
checkEquality(<Map<String, Object>>[
6565
{'reflect(o1)': reflect(o1), 'reflect(o1), again': reflect(o1)},
6666
{'reflect(o2)': reflect(o2), 'reflect(o2), again': reflect(o2)},
6767
{

tests/lib_2/mirrors/fake_function_with_call_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class WannabeFunction {
2323
main() {
2424
Expect.isTrue(new WannabeFunction() is Function);
2525

26-
ClosureMirror cm = reflect(new WannabeFunction());
26+
ClosureMirror cm = reflect(new WannabeFunction()) as ClosureMirror;
2727
Expect.equals(7, cm.invoke(#call, [3, 4]).reflectee);
2828
Expect.throwsNoSuchMethodError(() => cm.invoke(#call, [3]), "Wrong arity");
2929
Expect.equals(49, cm.invoke(#method, [7]).reflectee);

0 commit comments

Comments
 (0)