mirror of
https://github.com/dart-lang/sdk
synced 2024-11-02 12:24:24 +00:00
1f55b7ca10
This is a reland of 8a21ab195a
Original change's description:
> [VM/runtime] Refactor the representation of type parameters in the VM.
>
> This introduces a new VM internal class 'TypeParameters' representing the declaration of a list of type parameters, either in a class or function.
> The reference to (or use of) a type parameter is still represented by the existing 'TypeParameter' class.
>
> Fixes https://github.com/dart-lang/sdk/issues/43901
> Fixes https://github.com/dart-lang/sdk/issues/45763
>
> TEST=existing ones and a regression test
>
> Change-Id: I1fde808bf753cc1cb829f2c4383c1836651cee80
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/189942
> Commit-Queue: Régis Crelier <regis@google.com>
> Reviewed-by: Alexander Markov <alexmarkov@google.com>
This fixes https://github.com/dart-lang/sdk/issues/45911
TEST=existing ones and a regression test
Change-Id: I709d38b1df3d73fe3c9796d5aca3cbbdcf77fd38
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/198380
Commit-Queue: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
155 lines
6.2 KiB
Dart
155 lines
6.2 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.
|
|
|
|
library test.type_arguments_test;
|
|
|
|
import 'dart:mirrors';
|
|
|
|
import 'package:expect/expect.dart';
|
|
import 'generics_helper.dart';
|
|
|
|
class A<T> {}
|
|
|
|
class Z<T> {}
|
|
|
|
class B extends A {}
|
|
|
|
class C
|
|
extends A<num, int> //# 01: compile-time error
|
|
{}
|
|
|
|
class D extends A<int> {}
|
|
|
|
class E<S> extends A<S> {}
|
|
|
|
class F<R> extends A<int> {}
|
|
|
|
class G {}
|
|
|
|
class H<A, B, C> {}
|
|
|
|
class I extends G {}
|
|
|
|
main() {
|
|
// Declarations.
|
|
typeParameters(reflectClass(G), []);
|
|
typeParameters(reflectClass(B), []);
|
|
typeParameters(reflectClass(C), []);
|
|
typeParameters(reflectClass(D), []);
|
|
typeParameters(reflectClass(G), []);
|
|
typeParameters(reflectClass(I), []);
|
|
|
|
typeArguments(reflectClass(A), []);
|
|
typeArguments(reflectClass(B), []);
|
|
typeArguments(reflectClass(C), []);
|
|
typeArguments(reflectClass(D), []);
|
|
typeArguments(reflectClass(E), []);
|
|
typeArguments(reflectClass(F), []);
|
|
typeArguments(reflectClass(G), []);
|
|
typeArguments(reflectClass(H), []);
|
|
typeArguments(reflectClass(I), []);
|
|
|
|
Expect.isTrue(reflectClass(A).isOriginalDeclaration);
|
|
Expect.isTrue(reflectClass(B).isOriginalDeclaration);
|
|
Expect.isTrue(reflectClass(C).isOriginalDeclaration);
|
|
Expect.isTrue(reflectClass(D).isOriginalDeclaration);
|
|
Expect.isTrue(reflectClass(E).isOriginalDeclaration);
|
|
Expect.isTrue(reflectClass(F).isOriginalDeclaration);
|
|
Expect.isTrue(reflectClass(G).isOriginalDeclaration);
|
|
Expect.isTrue(reflectClass(H).isOriginalDeclaration);
|
|
Expect.isTrue(reflectClass(I).isOriginalDeclaration);
|
|
|
|
Expect.equals(reflectClass(A), reflectClass(A).originalDeclaration);
|
|
Expect.equals(reflectClass(B), reflectClass(B).originalDeclaration);
|
|
Expect.equals(reflectClass(C), reflectClass(C).originalDeclaration);
|
|
Expect.equals(reflectClass(D), reflectClass(D).originalDeclaration);
|
|
Expect.equals(reflectClass(E), reflectClass(E).originalDeclaration);
|
|
Expect.equals(reflectClass(F), reflectClass(F).originalDeclaration);
|
|
Expect.equals(reflectClass(G), reflectClass(G).originalDeclaration);
|
|
Expect.equals(reflectClass(H), reflectClass(H).originalDeclaration);
|
|
Expect.equals(reflectClass(I), reflectClass(I).originalDeclaration);
|
|
|
|
// Instantiations.
|
|
typeParameters(reflect(new B()).type, []);
|
|
typeParameters(reflect(new C()).type, []);
|
|
typeParameters(reflect(new D()).type, []);
|
|
typeParameters(reflect(new G()).type, []);
|
|
typeParameters(reflect(new I()).type, []);
|
|
|
|
var numMirror = reflectClass(num);
|
|
var dynamicMirror = currentMirrorSystem().dynamicType;
|
|
typeArguments(reflect(new A<num>()).type, [numMirror]);
|
|
typeArguments(reflect(new A<dynamic>()).type, [dynamicMirror]);
|
|
typeArguments(reflect(new A()).type, [dynamicMirror]);
|
|
typeArguments(reflect(new B()).type, []);
|
|
typeArguments(reflect(new C()).type, []);
|
|
typeArguments(reflect(new D()).type, []);
|
|
typeArguments(reflect(new E<num>()).type, [numMirror]);
|
|
typeArguments(reflect(new E<dynamic>()).type, [dynamicMirror]);
|
|
typeArguments(reflect(new E()).type, [dynamicMirror]);
|
|
typeArguments(reflect(new F<num>()).type, [numMirror]);
|
|
typeArguments(reflect(new F<dynamic>()).type, [dynamicMirror]);
|
|
typeArguments(reflect(new F()).type, [dynamicMirror]);
|
|
typeArguments(reflect(new G()).type, []);
|
|
typeArguments(reflect(new H<dynamic, num, dynamic>()).type,
|
|
[dynamicMirror, numMirror, dynamicMirror]);
|
|
typeArguments(reflect(new I()).type, []);
|
|
|
|
Expect.isFalse(reflect(new A<num>()).type.isOriginalDeclaration);
|
|
Expect.isTrue(reflect(new B()).type.isOriginalDeclaration);
|
|
Expect.isTrue(reflect(new C()).type.isOriginalDeclaration);
|
|
Expect.isTrue(reflect(new D()).type.isOriginalDeclaration);
|
|
Expect.isFalse(reflect(new E<num>()).type.isOriginalDeclaration);
|
|
Expect.isFalse(reflect(new F<num>()).type.isOriginalDeclaration);
|
|
Expect.isTrue(reflect(new G()).type.isOriginalDeclaration);
|
|
Expect.isFalse(reflect(new H()).type.isOriginalDeclaration);
|
|
Expect.isTrue(reflect(new I()).type.isOriginalDeclaration);
|
|
|
|
Expect.equals(
|
|
reflectClass(A), reflect(new A<num>()).type.originalDeclaration);
|
|
Expect.equals(reflectClass(B), reflect(new B()).type.originalDeclaration);
|
|
Expect.equals(reflectClass(C), reflect(new C()).type.originalDeclaration);
|
|
Expect.equals(reflectClass(D), reflect(new D()).type.originalDeclaration);
|
|
Expect.equals(
|
|
reflectClass(E), reflect(new E<num>()).type.originalDeclaration);
|
|
Expect.equals(
|
|
reflectClass(F), reflect(new F<num>()).type.originalDeclaration);
|
|
Expect.equals(reflectClass(G), reflect(new G()).type.originalDeclaration);
|
|
Expect.equals(reflectClass(H), reflect(new H()).type.originalDeclaration);
|
|
Expect.equals(reflectClass(I), reflect(new I()).type.originalDeclaration);
|
|
|
|
Expect.notEquals(reflect(new A<num>()).type,
|
|
reflect(new A<num>()).type.originalDeclaration);
|
|
Expect.equals(
|
|
reflect(new B()).type, reflect(new B()).type.originalDeclaration);
|
|
Expect.equals(
|
|
reflect(new C()).type, reflect(new C()).type.originalDeclaration);
|
|
Expect.equals(
|
|
reflect(new D()).type, reflect(new D()).type.originalDeclaration);
|
|
Expect.notEquals(reflect(new E<num>()).type,
|
|
reflect(new E<num>()).type.originalDeclaration);
|
|
Expect.notEquals(reflect(new F<num>()).type,
|
|
reflect(new F<num>()).type.originalDeclaration);
|
|
Expect.equals(
|
|
reflect(new G()).type, reflect(new G()).type.originalDeclaration);
|
|
Expect.notEquals(
|
|
reflect(new H()).type, reflect(new H()).type.originalDeclaration);
|
|
Expect.equals(
|
|
reflect(new I()).type, reflect(new I()).type.originalDeclaration);
|
|
|
|
// Library members are all uninstantiated generics or non-generics.
|
|
currentMirrorSystem().libraries.values.forEach((libraryMirror) {
|
|
libraryMirror.declarations.values.forEach((declaration) {
|
|
if (declaration is ClassMirror) {
|
|
Expect.isTrue(declaration.isOriginalDeclaration);
|
|
Expect.equals(declaration, declaration.originalDeclaration);
|
|
}
|
|
});
|
|
});
|
|
|
|
Expect.equals(reflectClass(A).typeVariables[0].owner, reflectClass(A));
|
|
Expect.equals(reflectClass(Z).typeVariables[0].owner, reflectClass(Z));
|
|
Expect.equals(
|
|
reflectClass(A).typeVariables[0], reflectClass(A).typeVariables[0]);
|
|
}
|