mirror of
https://github.com/dart-lang/sdk
synced 2024-11-05 18:22:09 +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>
64 lines
2.9 KiB
Dart
64 lines
2.9 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.generic_bounded;
|
|
|
|
import 'dart:mirrors';
|
|
|
|
import 'package:expect/expect.dart';
|
|
|
|
import 'generics_helper.dart';
|
|
|
|
class Super<T extends num> {}
|
|
|
|
class Fixed extends Super<int> {}
|
|
class Generic<R> extends Super<R> {} // //# 02: compile-time error
|
|
class Malbounded extends Super<String> {} //# 01: compile-time error
|
|
|
|
main() {
|
|
ClassMirror superDecl = reflectClass(Super);
|
|
ClassMirror superOfInt = reflectClass(Fixed).superclass;
|
|
ClassMirror genericDecl = reflectClass(Generic); // //# 02: continued
|
|
ClassMirror superOfR = genericDecl.superclass; // //# 02: continued
|
|
ClassMirror genericOfDouble = reflect(new Generic<double>()).type; // //# 02: continued
|
|
ClassMirror superOfDouble = genericOfDouble.superclass; // //# 02: continued
|
|
ClassMirror genericOfBool = reflect(new Generic<bool>()).type; // //# 02: compile-time error
|
|
ClassMirror superOfBool = genericOfBool.superclass; // //# 02: continued
|
|
Expect.isFalse(genericOfBool.isOriginalDeclaration); // //# 02: continued
|
|
Expect.isFalse(superOfBool.isOriginalDeclaration); // //# 02: continued
|
|
typeParameters(genericOfBool, [#R]); // //# 02: continued
|
|
typeParameters(superOfBool, [#T]); // //# 02: continued
|
|
typeArguments(genericOfBool, [reflectClass(bool)]); // //# 02: continued
|
|
typeArguments(superOfBool, [reflectClass(bool)]); // //# 02: continued
|
|
|
|
ClassMirror superOfString = reflectClass(Malbounded).superclass; // //# 01: continued
|
|
|
|
Expect.isTrue(superDecl.isOriginalDeclaration);
|
|
Expect.isFalse(superOfInt.isOriginalDeclaration);
|
|
Expect.isTrue(genericDecl.isOriginalDeclaration); // //# 02: continued
|
|
Expect.isFalse(superOfR.isOriginalDeclaration); // //# 02: continued
|
|
Expect.isFalse(genericOfDouble.isOriginalDeclaration); // //# 02: continued
|
|
Expect.isFalse(superOfDouble.isOriginalDeclaration); // //# 02: continued
|
|
|
|
Expect.isFalse(superOfString.isOriginalDeclaration); // //# 01: continued
|
|
|
|
TypeVariableMirror tFromSuper = superDecl.typeVariables.single;
|
|
TypeVariableMirror rFromGeneric = genericDecl.typeVariables.single; // //# 02: continued
|
|
|
|
Expect.equals(reflectClass(num), tFromSuper.upperBound);
|
|
Expect.equals(reflectClass(Object), rFromGeneric.upperBound); // //# 02: continued
|
|
|
|
// Names of type variables are not preserved after type canonicalization
|
|
// and are therefore not compared to expected names.
|
|
|
|
typeArguments(superDecl, []);
|
|
typeArguments(superOfInt, [reflectClass(int)]);
|
|
typeArguments(genericDecl, []); // //# 02: continued
|
|
typeArguments(superOfR, [rFromGeneric]); // //# 02: continued
|
|
typeArguments(genericOfDouble, [reflectClass(double)]); // //# 02: continued
|
|
typeArguments(superOfDouble, [reflectClass(double)]); // //# 02: continued
|
|
typeArguments(superOfString, [reflectClass(String)]); // //# 01: continued
|
|
}
|