mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +00:00
df97aca1fa
Closes https://github.com/dart-lang/sdk/pull/50764 GitOrigin-RevId: ee2fe9a75d50e877f4ad2fe3743acdbc04f186ef Change-Id: Ia73cd22da4e6ec95e84772aa4e1345ce2dbde215 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/276360 Reviewed-by: Erik Ernst <eernst@google.com> Commit-Queue: Erik Ernst <eernst@google.com>
48 lines
1.6 KiB
Dart
48 lines
1.6 KiB
Dart
// Copyright (c) 2013, 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.
|
|
|
|
// @dart = 2.9
|
|
|
|
library test.instantiate_abstract_class;
|
|
|
|
import 'dart:mirrors';
|
|
import 'package:expect/expect.dart';
|
|
|
|
assertInstantiationErrorOnGenerativeConstructors(classMirror) {
|
|
classMirror.declarations.values.forEach((decl) {
|
|
if (decl is! MethodMirror) return;
|
|
if (!decl.isGenerativeConstructor) return;
|
|
var args = new List.filled(decl.parameters.length, null);
|
|
Expect.throws(
|
|
() => classMirror.newInstance(decl.constructorName, args),
|
|
(e) => e is AbstractClassInstantiationError,
|
|
'${decl.qualifiedName} should have failed');
|
|
});
|
|
}
|
|
|
|
runFactoryConstructors(classMirror) {
|
|
classMirror.declarations.values.forEach((decl) {
|
|
if (decl is! MethodMirror) return;
|
|
if (!decl.isFactoryConstructor) return;
|
|
var args = new List.filled(decl.parameters.length, null);
|
|
classMirror.newInstance(decl.constructorName, args); // Should not throw.
|
|
});
|
|
}
|
|
|
|
abstract class AbstractClass {
|
|
AbstractClass();
|
|
AbstractClass.named();
|
|
factory AbstractClass.named2() => new ConcreteClass();
|
|
}
|
|
|
|
class ConcreteClass implements AbstractClass {}
|
|
|
|
main() {
|
|
assertInstantiationErrorOnGenerativeConstructors(reflectType(num));
|
|
assertInstantiationErrorOnGenerativeConstructors(reflectType(double));
|
|
assertInstantiationErrorOnGenerativeConstructors(reflectType(StackTrace));
|
|
|
|
assertInstantiationErrorOnGenerativeConstructors(reflectType(AbstractClass));
|
|
runFactoryConstructors(reflectType(AbstractClass));
|
|
}
|