Skip to content
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

#2080. Add correct member overrides tests. Part 2. Setters #2093

Merged
merged 1 commit into from
Jun 22, 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
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class C2 implements I1, I2, I3 {
// [cfe] unspecified

void m2(int v1, {String s0 = ""}) {}
// ^
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 m and m′ be member signatures with the same name id. Then m
/// is a correct override of m′ iff the following criteria are all satisfied:
/// ...
/// • If m and m′ are both methods or both setters: Let F be the function type
/// of m except that the parameter type is the built-in class Object for each
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would expect to see Object? instead of Object in this line. Could you point me to the part of the spec this quote is taken from?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since it's a comment, it can be resolved in a follow-up.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! That looks interesting :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With null safety, that should be Object?.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think it should be Object? too, but the spec does say Object. Should we update the spec as well?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Spec updates for null safety are in review (...since september 2021...). It is in the PR dart-lang/language#2605: It was missing, but I just corrected that. So it will be landed along with all the other null safety changes.

/// parameter of m which is covariant-by-declaration. Let F′ be the function
/// type of m′. F must then be a subtype of F′.
///
/// @description Checks that it is a compile-time error if `m` and `m′` are both
/// setters and function type `m` is not a subtype of `m′`. Test `implements`
/// clause
/// @author [email protected]

interface class I {
void set m(num n) {}
}

class C implements I {
void set m(int i) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

mixin M implements I {
void set m(int i) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(M);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 m and m′ be member signatures with the same name id. Then m
/// is a correct override of m′ iff the following criteria are all satisfied:
/// ...
/// • If m and m′ are both methods or both setters: Let F be the function type
/// of m except that the parameter type is the built-in class Object for each
/// parameter of m which is covariant-by-declaration. Let F′ be the function
/// type of m′. F must then be a subtype of F′.
///
/// @description Checks that it is a compile-time error if `m` and `m′` are both
/// setters and function type `m` is not a subtype of `m′`. Test `implements`
/// clause
/// @author [email protected]

interface class I1 {
void set m(int i) {}
}

interface class I2 {
void set m(Object i) {}
}

class C implements I1, I2 {
void set m(num i) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

mixin M implements I1, I2 {
void set m(num i) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(M);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 m and m′ be member signatures with the same name id. Then m
/// is a correct override of m′ iff the following criteria are all satisfied:
/// ...
/// • If m and m′ are both methods or both setters: Let F be the function type
/// of m except that the parameter type is the built-in class Object for each
/// parameter of m which is covariant-by-declaration. Let F′ be the function
/// type of m′. F must then be a subtype of F′.
///
/// @description Checks that it is not an error if `m` and `m′` are both setters
/// and function type `m` is a subtype of `m′. Test `implements` clause
/// @author [email protected]

interface class I {
void set m1(num v1) {}
void set m2(covariant int v1) {}
}

class C implements I {
void set m1(covariant int i) {}
void set m2(num i) {}
}

mixin M implements I {
void set m1(covariant int i) {}
void set m2(num i) {}
}

main() {
print(C);
print(M);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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 m and m′ be member signatures with the same name id. Then m
/// is a correct override of m′ iff the following criteria are all satisfied:
/// ...
/// • If m and m′ are both methods or both setters: Let F be the function type
/// of m except that the parameter type is the built-in class Object for each
/// parameter of m which is covariant-by-declaration. Let F′ be the function
/// type of m′. F must then be a subtype of F′.
///
/// @description Checks that it is not an error if `m` and `m′` are both setters
/// and function type `m` is a subtype of `m′. Test `implements` clause
/// @author [email protected]

interface class I1 {
void set m(num v1) {}
}

interface class I2 {
void set m(covariant int v1) {}
}

class C implements I1, I2 {
void set m(covariant int i) {}
}

mixin M implements I1, I2 {
void set m(num i) {}
}

main() {
print(C);
print(M);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// 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 m and m′ be member signatures with the same name id. Then m
/// is a correct override of m′ iff the following criteria are all satisfied:
/// ...
/// • If m and m′ are both methods or both setters: Let F be the function type
/// of m except that the parameter type is the built-in class Object for each
/// parameter of m which is covariant-by-declaration. Let F′ be the function
/// type of m′. F must then be a subtype of F′.
///
/// @description Checks that it is a compile-time error if `m` and `m′` are both
/// setters and function type `m` is not a subtype of `m′. Test `implements`
/// clause
/// @author [email protected]

interface class I {
void set m1(num v1) {}
void set m2(covariant int v1) {}
}

class C implements I {
void set m1(covariant String i) {}
// ^^
// [analyzer] unspecified
// [cfe] unspecified

void set m2(String i) {}
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

mixin M implements I {
void set m1(covariant String i) {}
// ^^
// [analyzer] unspecified
// [cfe] unspecified

void set m2(String i) {}
// ^^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(M);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// 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 m and m′ be member signatures with the same name id. Then m
/// is a correct override of m′ iff the following criteria are all satisfied:
/// ...
/// • If m and m′ are both methods or both setters: Let F be the function type
/// of m except that the parameter type is the built-in class Object for each
/// parameter of m which is covariant-by-declaration. Let F′ be the function
/// type of m′. F must then be a subtype of F′.
///
/// @description Checks that it is a compile-time error if `m` and `m′` are both
/// setters and function type `m` is not a subtype of `m′`. Test `extends` and
/// `on` clauses
/// @author [email protected]

interface class I {
void set m(num n) {}
}

class C extends I {
void set m(int i) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

mixin M on I {
void set m(int i) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(M);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// 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 m and m′ be member signatures with the same name id. Then m
/// is a correct override of m′ iff the following criteria are all satisfied:
/// ...
/// • If m and m′ are both methods or both setters: Let F be the function type
/// of m except that the parameter type is the built-in class Object for each
/// parameter of m which is covariant-by-declaration. Let F′ be the function
/// type of m′. F must then be a subtype of F′.
///
/// @description Checks that it is a compile-time error if `m` and `m′` are both
/// setters and function type `m` is not a subtype of `m′`. Test `extends` and
/// `on` clauses
/// @author [email protected]

interface class I1 {
void set m(int i) {}
}

interface class I2 {
void set m(Object i) {}
}

class C extends I1 implements I2 {
void set m(num i) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

mixin M on I2 implements I1 {
void set m(num i) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
print(M);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// 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 m and m′ be member signatures with the same name id. Then m
/// is a correct override of m′ iff the following criteria are all satisfied:
/// ...
/// • If m and m′ are both methods or both setters: Let F be the function type
/// of m except that the parameter type is the built-in class Object for each
/// parameter of m which is covariant-by-declaration. Let F′ be the function
/// type of m′. F must then be a subtype of F′.
///
/// @description Checks that it is not an error if `m` and `m′` are both setters
/// and function type `m` is a subtype of `m′. Test `extends` and `on` clauses
/// @author [email protected]

interface class I {
void set m1(num v1) {}
void set m2(covariant int v1) {}
}

class C extends I {
void set m1(covariant int i) {}
void set m2(num i) {}
}

mixin M on I {
void set m1(covariant int i) {}
void set m2(num i) {}
}

main() {
print(C);
print(M);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// 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 m and m′ be member signatures with the same name id. Then m
/// is a correct override of m′ iff the following criteria are all satisfied:
/// ...
/// • If m and m′ are both methods or both setters: Let F be the function type
/// of m except that the parameter type is the built-in class Object for each
/// parameter of m which is covariant-by-declaration. Let F′ be the function
/// type of m′. F must then be a subtype of F′.
///
/// @description Checks that it is not an error if `m` and `m′` are both setters
/// and function type `m` is a subtype of `m′. Test `extends` and `on` clauses
/// @author [email protected]

interface class I1 {
void set m(num v1) {}
}

interface class I2 {
void set m(covariant int v1) {}
}

class C extends I1 implements I2 {
void set m(covariant int i) {}
}

mixin M on I2 implements I1 {
void set m(num i) {}
}

main() {
print(C);
print(M);
}
Loading