dart-sdk/tests/lib/mirrors/generic_mixin_applications_test.dart
Robert Nystrom 7ca5ad46ce Set tests that have mixin errors as 2.19.
Mark tests that contain errors about using a class as a mixin to use
language version 2.19 where that's not an error.

This may not fix all of the tests because it's the language version of
the library where the class is declared that matters, not where the
class is used as a mixin. But most tests have all of their declarations
in the same library, so this should fix most.

Change-Id: I910439ebd2f10f731418dc588b7e4619a0841c16
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/285923
Reviewed-by: Jake Macdonald <jakemac@google.com>
Commit-Queue: Jake Macdonald <jakemac@google.com>
2023-03-01 15:03:39 +00:00

112 lines
5.1 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.
// TODO(51557): Decide if the mixins being applied in this test should be
// "mixin", "mixin class" or the test should be left at 2.19.
// @dart=2.19
library test.generic_mixin_applications;
import 'dart:mirrors';
import 'package:expect/expect.dart';
import 'generics_helper.dart';
class Super<S> {}
class Mixin<M> {}
class Nixim<N> {}
class NonGenericMixinApplication1 = Super with Mixin;
class NonGenericMixinApplication2 = Super<num> with Mixin<String>;
class GenericMixinApplication1<MA> = Super<MA> with Mixin<MA>;
class GenericMixinApplication2<MA> = Super<num> with Mixin<String>;
class NonGenericClass1 extends Super with Mixin {}
class NonGenericClass2 extends Super<num> with Mixin<String> {}
class GenericClass1<C> extends Super<C> with Mixin<C> {}
class GenericClass2<C> extends Super<num> with Mixin<String> {}
class GenericMultipleMixins<A, B, C> extends Super<A> with Mixin<B>, Nixim<C> {}
main() {
TypeMirror dynamicMirror = currentMirrorSystem().dynamicType;
// Declarations.
typeParameters(reflectClass(NonGenericMixinApplication1), []);
typeParameters(reflectClass(NonGenericMixinApplication2), []);
typeParameters(reflectClass(GenericMixinApplication1), [#MA]);
typeParameters(reflectClass(GenericMixinApplication2), [#MA]);
typeParameters(reflectClass(NonGenericClass1), []);
typeParameters(reflectClass(NonGenericClass2), []);
typeParameters(reflectClass(GenericClass1), [#C]);
typeParameters(reflectClass(GenericClass2), [#C]);
typeParameters(reflectClass(GenericMultipleMixins), [#A, #B, #C]);
// Anonymous mixin applications have no type parameters or type arguments.
typeParameters(reflectClass(NonGenericClass1).superclass, []);
typeParameters(reflectClass(NonGenericClass2).superclass, []);
typeParameters(reflectClass(GenericClass1).superclass, []);
typeParameters(reflectClass(GenericClass2).superclass, []);
typeArguments(reflectClass(NonGenericMixinApplication1), []);
typeArguments(reflectClass(NonGenericMixinApplication2), []);
typeArguments(reflectClass(GenericMixinApplication1), []);
typeArguments(reflectClass(GenericMixinApplication2), []);
typeArguments(reflectClass(NonGenericClass1), []);
typeArguments(reflectClass(NonGenericClass2), []);
typeArguments(reflectClass(GenericClass1), []);
typeArguments(reflectClass(GenericClass2), []);
typeArguments(reflectClass(GenericMultipleMixins), []);
// Anonymous mixin applications have no type parameters or type arguments.
typeArguments(
reflectClass(NonGenericClass1).superclass!.originalDeclaration, []);
typeArguments(
reflectClass(NonGenericClass2).superclass!.originalDeclaration, []);
typeArguments(
reflectClass(GenericClass1).superclass!.originalDeclaration, []);
typeArguments(
reflectClass(GenericClass2).superclass!.originalDeclaration, []);
// Instantiations.
typeParameters(reflect(new NonGenericMixinApplication1()).type, []);
typeParameters(reflect(new NonGenericMixinApplication2()).type, []);
typeParameters(reflect(new GenericMixinApplication1<bool>()).type, [#MA]);
typeParameters(reflect(new GenericMixinApplication2<bool>()).type, [#MA]);
typeParameters(reflect(new NonGenericClass1()).type, []);
typeParameters(reflect(new NonGenericClass2()).type, []);
typeParameters(reflect(new GenericClass1<bool>()).type, [#C]);
typeParameters(reflect(new GenericClass2<bool>()).type, [#C]);
typeParameters(reflect(new GenericMultipleMixins<bool, String, int>()).type,
[#A, #B, #C]);
// Anonymous mixin applications have no type parameters or type arguments.
typeParameters(reflect(new NonGenericClass1()).type.superclass!, []);
typeParameters(reflect(new NonGenericClass2()).type.superclass!, []);
typeParameters(reflect(new GenericClass1<bool>()).type.superclass!, []);
typeParameters(reflect(new GenericClass2<bool>()).type.superclass!, []);
typeArguments(reflect(new NonGenericMixinApplication1()).type, []);
typeArguments(reflect(new NonGenericMixinApplication2()).type, []);
typeArguments(
reflect(new GenericMixinApplication1<bool>()).type, [reflectClass(bool)]);
typeArguments(
reflect(new GenericMixinApplication2<bool>()).type, [reflectClass(bool)]);
typeArguments(reflect(new NonGenericClass1()).type, []);
typeArguments(reflect(new NonGenericClass2()).type, []);
typeArguments(reflect(new GenericClass1<bool>()).type, [reflectClass(bool)]);
typeArguments(reflect(new GenericClass2<bool>()).type, [reflectClass(bool)]);
typeArguments(reflect(new GenericMultipleMixins<bool, String, int>()).type,
[reflectClass(bool), reflectClass(String), reflectClass(int)]);
// Anonymous mixin applications have no type parameters or type arguments.
typeArguments(reflect(new NonGenericClass1()).type.superclass!, []);
typeArguments(reflect(new NonGenericClass2()).type.superclass!, []);
typeArguments(reflect(new GenericClass1<bool>()).type.superclass!, []);
typeArguments(reflect(new GenericClass2<bool>()).type.superclass!, []);
}