dart-sdk/tests/lib/mirrors/generics_dynamic_test.dart
Johnni Winther 62f84880ef [cfe] Report error on missing return from non-nullable function
Closes #40520
Closes #40948
Closes #40425

Change-Id: I0aa3cfa51b410c90dd0bea963846eeb6b2e73efb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/140540
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Dmitry Stefantsov <dmitryas@google.com>
2020-03-24 08:21:36 +00:00

69 lines
3 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.
import 'dart:mirrors';
import 'package:expect/expect.dart';
class A<T> {}
class B<T extends A> extends A implements C {
A m(A a) => a;
late A field;
}
class C<S, T> {}
class D extends A<int> {}
main() {
ClassMirror aDecl = reflectClass(A);
ClassMirror bDecl = reflectClass(B);
ClassMirror cDecl = reflectClass(C);
TypeMirror aInstance = reflect(new A()).type;
TypeMirror aInstanceDynamic = reflect(new A<dynamic>()).type;
TypeMirror dInstance = reflect(new D()).type;
TypeMirror cInstance = reflect(new C<dynamic, dynamic>()).type;
TypeMirror cNestedInstance = reflect(new C<C, dynamic>()).type;
TypeMirror cTypeArgument = cNestedInstance.typeArguments.first;
TypeMirror superA = bDecl.superclass!;
TypeMirror superC = bDecl.superinterfaces.single;
MethodMirror m = bDecl.declarations[#m] as MethodMirror;
VariableMirror field = bDecl.declarations[#field] as VariableMirror;
TypeMirror returnTypeA = m.returnType;
TypeMirror parameterTypeA = m.parameters.first.type;
TypeMirror fieldTypeA = field.type;
TypeMirror upperBoundA = bDecl.typeVariables.single.upperBound;
TypeMirror dynamicMirror = currentMirrorSystem().dynamicType;
Expect.isTrue(aDecl.isOriginalDeclaration);
Expect.isTrue(reflect(dInstance).type.isOriginalDeclaration);
Expect.isFalse(aInstance.isOriginalDeclaration);
Expect.isFalse(aInstanceDynamic.isOriginalDeclaration);
Expect.isFalse(superA.isOriginalDeclaration);
Expect.isFalse(superC.isOriginalDeclaration);
Expect.isFalse(returnTypeA.isOriginalDeclaration);
Expect.isFalse(parameterTypeA.isOriginalDeclaration);
Expect.isFalse(fieldTypeA.isOriginalDeclaration);
Expect.isFalse(upperBoundA.isOriginalDeclaration);
Expect.isFalse(cInstance.isOriginalDeclaration);
Expect.isFalse(cNestedInstance.isOriginalDeclaration);
Expect.isFalse(cTypeArgument.isOriginalDeclaration);
Expect.isTrue(aDecl.typeArguments.isEmpty);
Expect.isTrue(dInstance.typeArguments.isEmpty);
Expect.equals(dynamicMirror, aInstance.typeArguments.single);
Expect.equals(dynamicMirror, aInstanceDynamic.typeArguments.single);
Expect.equals(dynamicMirror, superA.typeArguments.single);
Expect.equals(dynamicMirror, superC.typeArguments.first);
Expect.equals(dynamicMirror, superC.typeArguments.last);
Expect.equals(dynamicMirror, returnTypeA.typeArguments.single);
Expect.equals(dynamicMirror, parameterTypeA.typeArguments.single);
Expect.equals(dynamicMirror, fieldTypeA.typeArguments.single);
Expect.equals(dynamicMirror, upperBoundA.typeArguments.single);
Expect.equals(dynamicMirror, cInstance.typeArguments.first);
Expect.equals(dynamicMirror, cInstance.typeArguments.last);
Expect.equals(dynamicMirror, cNestedInstance.typeArguments.last);
Expect.equals(dynamicMirror, cTypeArgument.typeArguments.first);
Expect.equals(dynamicMirror, cTypeArgument.typeArguments.last);
}