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

#2559. Add augmented expression tests for operators. Part 1 #2724

Merged
merged 1 commit into from
Jun 28, 2024
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
@@ -0,0 +1,55 @@
// 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 The exact result of an `augmented` expression depends on what is
/// being augmented, but it generally follows the same rules as any normal
/// identifier:
/// ...
/// - Augmenting operators: When augmenting an operator, `augmented` must be
/// followed by the operator. For example when augmenting `+` you must do
/// `augmented + 1`, and when augmenting `[]` you must do `augmented[<arg>]`.
/// These constructs invoke the augmented operator, and are the only valid
/// uses of `augmented` in these contexts.
///
/// @description Checks that it is a compile-time error to tear-off `augmented`
/// expression inside of an augmenting operator.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

import augment 'augmented_expression_A05_t01_lib1.dart';
import augment 'augmented_expression_A05_t01_lib2.dart';

const augmented = "Augmented constant, should not be used";

class C {
int operator +(Object other) => 42;
final augmented = "C.augmented, should not be used";
}

mixin M {
int operator +(Object other);
final augmented = "M.augmented, should not be used";
}

enum E {
e1;
int operator +(Object other) => 42;
final augmented = "E.augmented, should not be used";
}

class A {
final augmented = "A.augmented, should not be used";
}

extension Ext on A {
int operator +(Object other) => 42;
}

main() {
print(C);
print(M);
print(E);
print(A);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// 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 The exact result of an `augmented` expression depends on what is
/// being augmented, but it generally follows the same rules as any normal
/// identifier:
/// ...
/// - Augmenting operators: When augmenting an operator, `augmented` must be
/// followed by the operator. For example when augmenting `+` you must do
/// `augmented + 1`, and when augmenting `[]` you must do `augmented[<arg>]`.
/// These constructs invoke the augmented operator, and are the only valid
/// uses of `augmented` in these contexts.
///
/// @description Checks that it is a compile-time error to tear-off `augmented`
/// expression inside of an augmenting operator.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

augment library 'augmented_expression_A05_t01.dart';

augment class C {
augment int operator +(Object other) {
var f = augmented;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return 0;
}
}

augment mixin M {
augment int operator +(Object other) {
var f = augmented;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return 0;
}
}

augment enum E {
augment e1;
augment int operator +(Object other) {
var f = augmented;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return 0;
}
}

augment extension Ext {
augment int operator +(Object other) {
var f = augmented;
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
// 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 The exact result of an `augmented` expression depends on what is
/// being augmented, but it generally follows the same rules as any normal
/// identifier:
/// ...
/// - Augmenting operators: When augmenting an operator, `augmented` must be
/// followed by the operator. For example when augmenting `+` you must do
/// `augmented + 1`, and when augmenting `[]` you must do `augmented[<arg>]`.
/// These constructs invoke the augmented operator, and are the only valid
/// uses of `augmented` in these contexts.
///
/// @description Checks that it is a compile-time error to tear-off `augmented`
/// expression inside of an augmenting operator.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

augment library 'augmented_expression_A05_t01.dart';

augment class C {
augment int operator +(Object other) {
var f = augmented.toString();
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return 0;
}
}

augment mixin M {
augment int operator +(Object other) {
var f = augmented.toString();
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return 0;
}
}

augment enum E {
augment e1;

augment int operator +(Object other) {
var f = augmented.toString();
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return 0;
}
}

augment extension Ext {
augment int operator +(Object other) {
var f = augmented.toString();
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
return 0;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// 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 The exact result of an `augmented` expression depends on what is
/// being augmented, but it generally follows the same rules as any normal
/// identifier:
/// ...
/// - Augmenting operators: When augmenting an operator, `augmented` must be
/// followed by the operator. For example when augmenting `+` you must do
/// `augmented + 1`, and when augmenting `[]` you must do `augmented[<arg>]`.
/// These constructs invoke the augmented operator, and are the only valid
/// uses of `augmented` in these contexts.
///
/// @description Checks that it is a compile-time error call `augmented()` as a
/// method inside of an augmenting operator.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

import augment 'augmented_expression_A05_t02_lib.dart';

String augmented(Object other) => "Top-level augmented(), should not be used";

class C {
String operator +(Object other) => "C";
String augmented(Object other) => "C.augmented(), should not be used";
}

mixin M {
String operator +(Object other);
String augmented(Object other) => "M.augmented(), should not be used";
}

enum E {
e1;
String operator +(Object other) => "E";
String augmented(Object other) => "E.augmented(), should not be used";
}

class A {
String augmented(Object other) => "A.augmented(), should not be used";
}

extension Ext on A {
String operator +(Object other) => "Ext";
}

main() {
print(C);
print(M);
print(E);
print(A);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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 The exact result of an `augmented` expression depends on what is
/// being augmented, but it generally follows the same rules as any normal
/// identifier:
/// ...
/// - Augmenting operators: When augmenting an operator, `augmented` must be
/// followed by the operator. For example when augmenting `+` you must do
/// `augmented + 1`, and when augmenting `[]` you must do `augmented[<arg>]`.
/// These constructs invoke the augmented operator, and are the only valid
/// uses of `augmented` in these contexts.
///
/// @description Checks that it is a compile-time error call `augmented()` as a
/// method inside of an augmenting operator.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

augment library 'augmented_expression_A05_t02.dart';

augment class C {
augment String operator +(Object other) {
return augmented(other);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}

augment mixin M {
augment String operator +(Object other) {
return augmented(other);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}

augment enum E {
augment e1;
augment String operator +(Object other) {
return augmented(other);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}

augment extension Ext {
augment String operator +(Object other) {
return augmented(other);
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// 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 The exact result of an `augmented` expression depends on what is
/// being augmented, but it generally follows the same rules as any normal
/// identifier:
/// ...
/// - Augmenting operators: When augmenting an operator, `augmented` must be
/// followed by the operator. For example when augmenting `+` you must do
/// `augmented + 1`, and when augmenting `[]` you must do `augmented[<arg>]`.
/// These constructs invoke the augmented operator, and are the only valid
/// uses of `augmented` in these contexts.
///
/// @description Checks that it is a compile-time error to declare a local
/// variable named `augmented` inside of an augmenting operator.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

import augment 'augmented_expression_A05_t03_lib.dart';

class C {
String operator +(Object other) => "C";
}

mixin M {
String operator +(Object other);
}

enum E {
e1;
String operator +(Object other) => "E";
}

class A {}

extension Ext on A {
String operator +(Object other) => "Ext";
}

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