Skip to content

#2112. Add missing tests for mixins. Part 2 #2118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 10, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions Language/Mixins/Mixin_Application/super_invocation_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// Copyright (c) 2023, 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.

/// @assertion Let S be a class, M be a mixin with required superinterfaces
/// T1, . . . , Tn, combined superinterface MS, implemented interfaces
/// I1, . . . , Ik and members as mixin member declarations, and let N be a name
/// ...
/// It is a compile-time error if any of members contains a super-invocation of
/// a member m (for example super.foo, super + 2, or super[1] = 2), and S does
/// not have a concrete implementation of m which is a valid override of the
/// member m in the interface MS
///
/// @description Checks that it is a compile-time error if any of members
/// contains a super-invocation of a member `m`, and `S` does not have a
/// concrete implementation of `m`
/// @author [email protected]

abstract class S {
bool get m;
S operator +(int other);
S operator [](int index);
}

mixin M1 on S {
void foo() {
super.m;
}
}

mixin M2 on S {
void foo() {
super + 2;
}
}

mixin M3 on S {
void foo() {
super[0];
}
}

abstract class C1 = S with M1;
// ^^
// [analyzer] unspecified
// [cfe] unspecified

abstract class C2 = S with M2;
// ^^
// [analyzer] unspecified
// [cfe] unspecified

abstract class C3 = S with M3;
// ^^
// [analyzer] unspecified
// [cfe] unspecified

main() {
print(C1);
print(C2);
print(C3);
}
46 changes: 46 additions & 0 deletions Language/Mixins/Mixin_Application/super_invocation_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright (c) 2023, 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.

/// @assertion Let S be a class, M be a mixin with required superinterfaces
/// T1, . . . , Tn, combined superinterface MS, implemented interfaces
/// I1, . . . , Ik and members as mixin member declarations, and let N be a name
/// ...
/// It is a compile-time error if any of members contains a super-invocation of
/// a member m (for example super.foo, super + 2, or super[1] = 2), and S does
/// not have a concrete implementation of m which is a valid override of the
/// member m in the interface MS
///
/// @description Checks that it is not an error if `S` does not have a concrete
/// implementation of a member `m` but there are no super-invocation of `m`
/// @author [email protected]

abstract class S {
bool get m;
S operator +(int other);
S operator [](int index);
}

mixin M1 on S {
void foo() {}
}

mixin M2 on S {
void foo() {}
}

mixin M3 on S {
void foo() {}
}

abstract class C1 = S with M1;

abstract class C2 = S with M2;

abstract class C3 = S with M3;

main() {
print(C1);
print(C2);
print(C3);
}
41 changes: 41 additions & 0 deletions Language/Mixins/Mixin_Application/super_invocation_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Copyright (c) 2023, 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.

/// @assertion Let S be a class, M be a mixin with required superinterfaces
/// T1, . . . , Tn, combined superinterface MS, implemented interfaces
/// I1, . . . , Ik and members as mixin member declarations, and let N be a name
/// ...
/// It is a compile-time error if any of members contains a super-invocation of
/// a member m (for example super.foo, super + 2, or super[1] = 2), and S does
/// not have a concrete implementation of m which is a valid override of the
/// member m in the interface MS
///
/// @description Checks that it is not an error if any of members contains a
/// super-invocation of a member `m`, and `S` does have a concrete
/// implementation of `m` which is a valid override of the member `m` in the
/// interface `MS`
/// @author [email protected]

class A {
Object m(num o) => o;
}

class S extends A {
num m(Object n) => 42;
}

mixin M on A {
void foo() {
super.m(3.14);
}
}

abstract class C1 = S with M;

abstract class C2 = A with M;

main() {
print(C1);
print(C2);
}