Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6abae96

Browse files
lrhnCommit Queue
authored and
Commit Queue
committed
Move tests/lib/mirrors off multi/mini-tests.
Make mirrors no longer able to create new instances of enum classes. (If that breaks anyone, they had it coming! It would invalidate exhaustiveness of switches and thereby soundness in general.) Also fix a number of failing tests, delete some no longer relevant tests (e.g. testing reflection of programs that won't compile, there are no runtime compilation errors any more.) Fix some more tests that were failing. Not all. Tested: Refactoring of existing tests. Change-Id: I558fe0ed45d23cac9eddbfdfa3d560d09195955d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/403587 Commit-Queue: Lasse Nielsen <lrn@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
1 parent d9bd666 commit 6abae96

File tree

68 files changed

+1741
-2175
lines changed

Some content is hidden

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

68 files changed

+1741
-2175
lines changed

‎pkg/expect/lib/expect.dart‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -618,17 +618,21 @@ class Expect {
618618
StringBuffer sb = StringBuffer("Expect.setEquals($msg) fails");
619619
// Report any missing items.
620620
if (missingElements.isNotEmpty) {
621-
sb.write('\nMissing expected elements:');
621+
sb.writeln('\nMissing expected elements:');
622622
for (final val in missingElements) {
623-
sb.write('$val ');
623+
sb
624+
..write('- ')
625+
..writeln(val);
624626
}
625627
}
626628

627629
// Report any extra items.
628630
if (extraElements.isNotEmpty) {
629-
sb.write('\nUnexpected elements:');
631+
sb.writeln('\nUnexpected elements:');
630632
for (final val in extraElements) {
631-
sb.write('$val ');
633+
sb
634+
..write('- ')
635+
..writeln(val);
632636
}
633637
}
634638

‎runtime/lib/mirrors.cc‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1397,6 +1397,13 @@ DEFINE_NATIVE_ENTRY(ClassMirror_invokeConstructor, 0, 5) {
13971397
UNREACHABLE();
13981398
}
13991399

1400+
if (klass.is_enum_class() && !lookup_constructor.IsFactory()) {
1401+
const Array& error_args = Array::Handle(Array::New(1));
1402+
error_args.SetAt(0, String::Handle(String::New("Cannot instantiate enum")));
1403+
Exceptions::ThrowByType(Exceptions::kUnsupported, error_args);
1404+
UNREACHABLE();
1405+
}
1406+
14001407
ASSERT(!type.IsNull());
14011408
TypeArguments& type_arguments = TypeArguments::Handle();
14021409
if (!type.IsInstantiated()) {

‎sdk/lib/_internal/vm/lib/mirrors_impl.dart‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ class _ClassMirror extends _ObjectMirror implements ClassMirror, _TypeMirror {
712712
List positionalArguments, [
713713
Map<Symbol, dynamic> namedArguments = const <Symbol, dynamic>{},
714714
]) {
715+
if (isEnum) throw UnsupportedError("Cannot instantiate enums");
715716
// Native code will add the 1 or 2 implicit arguments depending on whether
716717
// we end up invoking a factory or constructor respectively.
717718
int numPositionalArguments = positionalArguments.length;

‎tests/lib/mirrors/apply3_test.dart‎

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -13,47 +13,43 @@ class F {
1313
}
1414

1515
class G {
16-
call() =>'42';
16+
call(_, {a});
1717
noSuchMethod(Invocation invocation) => invocation;
1818
}
1919

2020
class H {
2121
call(required, {a}) => required + a;
2222
}
2323

24-
main() {
25-
Expect.equals('call', Function.apply(newF(), []));
26-
Expect.equals('call', Function.apply(newF(), [1]));
27-
Expect.equals('NSM', Function.apply(newF(), [1, 2]));
28-
Expect.equals('NSM', Function.apply(newF(), [1, 2, 3]));
24+
voidmain() {
25+
Expect.equals('call', Function.apply(F().call, []));
26+
Expect.equals('call', Function.apply(F().call, [1]));
27+
Expect.throwsNoSuchMethodError(() =>Function.apply(F().call, [1, 2]));
28+
Expect.throwsNoSuchMethodError(() =>Function.apply(F().call, [1, 2, 3]));
2929

30-
var symbol = const Symbol('a');
31-
var requiredParameters = [1];
32-
var optionalParameters = new Map<Symbol, int>()..[symbol] = 42;
33-
Invocation i = Function.apply(
34-
new G(),
35-
requiredParameters,
36-
optionalParameters,
37-
);
30+
const symbol = #a;
31+
var positionalArguments = <Object?>[1];
32+
var namedArguments = <Symbol, int>{symbol: 42};
33+
Invocation i = Function.apply(G().call, positionalArguments, namedArguments);
3834

39-
Expect.equals(constSymbol('call'), i.memberName);
40-
Expect.listEquals(requiredParameters, i.positionalArguments);
41-
Expect.mapEquals(optionalParameters, i.namedArguments);
35+
Expect.equals(#call, i.memberName);
36+
Expect.listEquals(positionalArguments, i.positionalArguments);
37+
Expect.mapEquals(namedArguments, i.namedArguments);
4238
Expect.isTrue(i.isMethod);
4339
Expect.isFalse(i.isGetter);
4440
Expect.isFalse(i.isSetter);
4541
Expect.isFalse(i.isAccessor);
4642

4743
// Check that changing the passed list and map for parameters does
4844
// not affect [i].
49-
requiredParameters[0] = 42;
50-
optionalParameters[symbol] = 12;
45+
positionalArguments[0] = 42;
46+
namedArguments[symbol] = 12;
5147
Expect.listEquals([1], i.positionalArguments);
52-
Expect.mapEquals(newMap()..[symbol] =42, i.namedArguments);
48+
Expect.mapEquals({symbol:42}, i.namedArguments);
5349

54-
// Check that using [i] for invocation yields the same [Invocation]
50+
// Check that delegating [i] to [G] yields equivalent [Invocation]
5551
// object.
56-
var mirror = reflect(newG());
52+
var mirror = reflect(G());
5753
Invocation other = mirror.delegate(i);
5854
Expect.equals(i.memberName, other.memberName);
5955
Expect.listEquals(i.positionalArguments, other.positionalArguments);
@@ -64,9 +60,9 @@ main() {
6460
Expect.equals(i.isAccessor, other.isAccessor);
6561

6662
// Test that [i] can be used to hit an existing method.
67-
Expect.equals(43, newH().call(1, a: 42));
68-
Expect.equals(43, Function.apply(newH(), [1], newMap()..[symbol] =42));
69-
mirror = reflect(newH());
63+
Expect.equals(43, H().call(1, a: 42));
64+
Expect.equals(43, Function.apply(H().call, [1], {symbol:42}));
65+
mirror = reflect(H());
7066
Expect.equals(43, mirror.delegate(i));
7167
Expect.equals(43, mirror.delegate(other));
7268
}

‎tests/lib/mirrors/circular_factory_redirection_test.dart‎

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /