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>
49 lines
1.7 KiB
Dart
49 lines
1.7 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.generics_substitution;
|
|
|
|
import 'dart:mirrors';
|
|
import 'package:expect/expect.dart';
|
|
|
|
class SuperGeneric<R, S> {
|
|
late R r;
|
|
s(S s) {}
|
|
}
|
|
|
|
class Generic<T> extends SuperGeneric<T, int> {
|
|
T t() => throw "does-not-return"; //
|
|
}
|
|
|
|
main() {
|
|
ClassMirror genericDecl = reflectClass(Generic);
|
|
ClassMirror genericOfString = reflect(new Generic<String>()).type;
|
|
ClassMirror superGenericDecl = reflectClass(SuperGeneric);
|
|
ClassMirror superOfTAndInt = genericDecl.superclass!;
|
|
ClassMirror superOfStringAndInt = genericOfString.superclass!;
|
|
|
|
Expect.isTrue(genericDecl.isOriginalDeclaration);
|
|
Expect.isFalse(genericOfString.isOriginalDeclaration);
|
|
Expect.isTrue(superGenericDecl.isOriginalDeclaration);
|
|
Expect.isFalse(superOfTAndInt.isOriginalDeclaration);
|
|
Expect.isFalse(superOfStringAndInt.isOriginalDeclaration);
|
|
|
|
Symbol r(ClassMirror cm) =>
|
|
(cm.declarations[#r] as VariableMirror).type.simpleName;
|
|
Symbol s(ClassMirror cm) =>
|
|
(cm.declarations[#s] as MethodMirror).parameters[0].type.simpleName;
|
|
Symbol t(ClassMirror cm) =>
|
|
(cm.declarations[#t] as MethodMirror).returnType.simpleName;
|
|
|
|
Expect.equals(#int, s(genericDecl.superclass!));
|
|
|
|
Expect.equals(#String, r(genericOfString.superclass!));
|
|
Expect.equals(#int, s(genericOfString.superclass!));
|
|
Expect.equals(#String, t(genericOfString));
|
|
|
|
Expect.equals(#int, s(superOfTAndInt));
|
|
|
|
Expect.equals(#String, r(superOfStringAndInt));
|
|
Expect.equals(#int, s(superOfStringAndInt));
|
|
}
|