dart-sdk/tests/language_2/mixin_type_parameter_inference_previous_mixin_test.dart
Lasse R.H. Nielsen 03765ed6ec Update old mixin tests. Remove the --super-mixins flag from the tests.
Bug: http://dartbug.com/34781
Change-Id: Ib07e1927e7de35ff0c48514b9e89da65a5f192dd
Reviewed-on: https://dart-review.googlesource.com/c/79700
Commit-Queue: Lasse R.H. Nielsen <lrn@google.com>
Reviewed-by: Leaf Petersen <leafp@google.com>
2018-10-23 08:35:49 +00:00

38 lines
1,005 B
Dart

// Copyright (c) 2018, 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 "package:expect/expect.dart";
abstract class A<T> {
// This is ok because type inference will ensure that in C, A and M are
// instantiated with the same T.
T f(T x) => x; //# 01: ok
}
class B {}
abstract class M1 implements A<B> {}
mixin M2<T> on A<T> {
T f(T x) => x;
T g(T x) => x;
Type h() => T;
}
// Inferred as `class C extends Object with M1, M2<B>`
class C extends Object with M1, M2 {}
main() {
C c = new C();
// M is instantiated with B, so C.g has type (B) -> B.
B Function(B) x = c.g; //# 02: ok
Null Function(Null) x = c.g; //# 03: compile-time error
Object Function(Object) x = c.g; //# 04: compile-time error
// And verify that the runtime system has the right type for the type
// parameter
Expect.equals(c.h(), B); //# 05: ok
}