blob: 503cf863b873e409fea2a7c89f5fa34aab0f677e [file] [log] [blame]
// Copyright (c) 2017, 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 covariant_override_test;
// This test contains cases where `covariant` is used as intended.
abstract class A {
A(this.f1, this.f2, this.f3);
// Normal usage, "by design": superclass requests covariance.
void m1(covariant Object o);
// Normal usage, "ad hoc": subclass requests covariance.
void m2(Object o);
// Syntactic special case: omit the type in subclass.
void m3(Object o);
// Positional optional arguments.
void m4([covariant Object o = 0]);
void m5([Object o = 0]);
void m6([Object o = 0]);
// Named arguments.
void m7({covariant Object arg = 0});
void m8({Object arg = 0});
void m9({Object arg = 0});
// Normal usage on field, "by design": superclass requests covariance.
covariant Object f1;
// Normal usage on field, "ad hoc": subclass requests covariance.
Object f2;
// Syntactic special case.
Object f3;
}
abstract class B extends A {
B(num f1, num f2, num f3) : super(f1, f2, f3);
void m1(num n);
void m2(covariant num n);
void m3(covariant n);
void m4([num n]);
void m5([covariant num n]);
void m6([covariant n]);
void m7({num arg});
void m8({covariant num arg});
void m9({covariant arg});
num get f1;
void set f1(num n);
num get f2;
void set f2(covariant num n);
void set f3(covariant n);
}
class C extends B {
C(int f1, int f2, int f3) : super(f1, f2, f3);
void m1(int i) {}
void m2(int i) {}
void m3(int i) {}
void m4([int i = 0]) {}
void m5([int i = 0]) {}
void m6([int i = 0]) {}
void m7({int arg = 0}) {}
void m8({int arg = 0}) {}
void m9({int arg = 0}) {}
int get f1 => 0;
void set f1(covariant int i) {}
int get f2 => 0;
void set f2(covariant int i) {}
int get f3 => 0;
void set f3(int i) {}
}
main() {
// For Dart 1.x, `covariant` has no runtime semantics; we just ensure
// that the code is not unused, such that we know it will be parsed.
A a = new C(39, 40, 41);
a.m1(42);
a.m2(42);
a.m3(42);
a.m4(42);
a.m5(42);
a.m6(42);
a.m7(arg: 42);
a.m8(arg: 42);
a.m9(arg: 42);
a.f1 = 42;
a.f2 = 42;
a.f3 = 42;
}