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

#2976. Add more equality tests #3023

Merged
merged 1 commit into from
Jan 6, 2025
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
73 changes: 73 additions & 0 deletions LanguageFeatures/Static-access-shorthand/equality_A02_t09.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// Copyright (c) 2024, 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 For `==`, we special-case when the right operand is (precisely!)
/// a static member shorthand.
/// ...
/// This special-casing is only against an immediate static member shorthand. It
/// does not change the context type of the second operand, so it would not work
/// with, for example, `Endian.host == wantBig ? .big : .little`. Here the
/// second operand is not a `<staticMemberShorthand>`, so it won't have a
/// shorthand context set, and the context type of the second operand of `==` is
/// the empty context `_`. (It's neither the static type of the first operand,
/// nor the parameter type of the first operand's `operator==`.)
///
/// @description Checks that it is a compile-time error to use a shorthand
/// expression in a left side of a (not)equality operator or in a wrong context
/// type. Test a class.
/// @author [email protected]

// SharedOptions=--enable-experiment=enum-shorthands

class C {
C();
C.id();
factory C.f() => C();

static C get staticGetter => C();
static C staticMethod() => C();
static final C instance = C();
}

main() {
if (.new() == C()) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.id() != C()) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.f() == C()) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.staticGetter != C()) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.staticMethod() == C()) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.instance != C()) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if ((C() as Object) == .new()) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if ((C() as Object) != .instance) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
56 changes: 56 additions & 0 deletions LanguageFeatures/Static-access-shorthand/equality_A02_t10.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
// Copyright (c) 2024, 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 For `==`, we special-case when the right operand is (precisely!)
/// a static member shorthand.
/// ...
/// This special-casing is only against an immediate static member shorthand. It
/// does not change the context type of the second operand, so it would not work
/// with, for example, `Endian.host == wantBig ? .big : .little`. Here the
/// second operand is not a `<staticMemberShorthand>`, so it won't have a
/// shorthand context set, and the context type of the second operand of `==` is
/// the empty context `_`. (It's neither the static type of the first operand,
/// nor the parameter type of the first operand's `operator==`.)
///
/// @description Checks that it is a compile-time error to use a shorthand
/// expression in a left side of a (not)equality operator or in a wrong context
/// type. Test a mixin.
/// @author [email protected]

// SharedOptions=--enable-experiment=enum-shorthands

mixin M {
static M get staticGetter => MC();
static M staticMethod() => MC();
static final M instance = MC();
}

class MC = Object with M;

main() {
if (.staticGetter != MC()) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.staticMethod() == MC()) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.instance != MC()) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if ((MC() as Object) == .staticMethod()) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if ((MC() as Object) != .instance) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
61 changes: 61 additions & 0 deletions LanguageFeatures/Static-access-shorthand/equality_A02_t11.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Copyright (c) 2024, 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 For `==`, we special-case when the right operand is (precisely!)
/// a static member shorthand.
/// ...
/// This special-casing is only against an immediate static member shorthand. It
/// does not change the context type of the second operand, so it would not work
/// with, for example, `Endian.host == wantBig ? .big : .little`. Here the
/// second operand is not a `<staticMemberShorthand>`, so it won't have a
/// shorthand context set, and the context type of the second operand of `==` is
/// the empty context `_`. (It's neither the static type of the first operand,
/// nor the parameter type of the first operand's `operator==`.)
///
/// @description Checks that it is a compile-time error to use a shorthand
/// expression in a left side of a (not)equality operator or in a wrong context
/// type. Test an enum.
/// @author [email protected]

// SharedOptions=--enable-experiment=enum-shorthands

enum E {
e0, e1;
const E();

static E get staticGetter => E.e0;
static E staticMethod() => E.e1;
}

main() {
if (.e0 == E.e0) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.staticGetter != E.e0) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.staticMethod() == E.e1) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.values[0] != E.e1) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if ((E.e0 as Object) == .e0) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if ((E.e0 as Object) != .staticGetter) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
72 changes: 72 additions & 0 deletions LanguageFeatures/Static-access-shorthand/equality_A02_t12.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2024, 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 For `==`, we special-case when the right operand is (precisely!)
/// a static member shorthand.
/// ...
/// This special-casing is only against an immediate static member shorthand. It
/// does not change the context type of the second operand, so it would not work
/// with, for example, `Endian.host == wantBig ? .big : .little`. Here the
/// second operand is not a `<staticMemberShorthand>`, so it won't have a
/// shorthand context set, and the context type of the second operand of `==` is
/// the empty context `_`. (It's neither the static type of the first operand,
/// nor the parameter type of the first operand's `operator==`.)
///
/// @description Checks that it is a compile-time error to use a shorthand
/// expression in a left side of a (not)equality operator or in a wrong context
/// type. Test an extension type.
/// @author [email protected]

// SharedOptions=--enable-experiment=enum-shorthands

extension type ET(int v) {
ET.id(this.v);
factory ET.f(int v) => ET(v);

static ET get staticGetter => ET(0);
static ET staticMethod() => ET(1);
static final ET instance = ET(2);
}

main() {
if (.new(0) == ET(0)) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.id(1) != ET(1)) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.f(2) == ET(2)) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.staticGetter != ET(0)) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.staticMethod() == ET(1)) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if (.instance != ET(2)) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if ((ET(0) as int) == .new(1)) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified

if ((ET(0) as int) != .instance) {}
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
Loading