-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
4 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
LanguageFeatures/Static-access-shorthand/equality_A02_t09.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
56
LanguageFeatures/Static-access-shorthand/equality_A02_t10.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
61
LanguageFeatures/Static-access-shorthand/equality_A02_t11.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
72
LanguageFeatures/Static-access-shorthand/equality_A02_t12.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |