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 tests for reserved word augmented in constructors. Part 2. #3015

Merged
merged 2 commits into from
Dec 16, 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
Expand Up @@ -12,7 +12,7 @@
/// must immediately be invoked.
///
/// @description Checks that it is a compile-time error to use `augmented` as a
/// constant value in a switch expressions and statements.
/// constant value in switch expressions and statements.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/// must immediately be invoked.
///
/// @description Checks that it is a compile-time error to use `augmented` as a
/// constant value in a switch expressions and statements.
/// constant value in switch expressions and statements.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ augment String topLevelFunction1([String v]) => "Augmented: $v";
augment String topLevelFunction2({String v}) => "Augmented: $v";

augment class C {
augment factory C.f1([String v = augmented]) => C("Augmented: $v");
augment factory C.f2({String v = augmented}) => C("Augmented: $v");
augment factory C.f1([String v]) => C("Augmented: $v");
augment factory C.f2({String v}) => C("Augmented: $v");
augment static String staticMethod1([String v]) => "Augmented: $v";
augment static String staticMethod2({String v}) => "Augmented: $v";
augment String instanceMethod1([String v]) => "Augmented: $v";
Expand Down Expand Up @@ -54,8 +54,8 @@ augment extension Ext {
}

augment extension type ET {
augment factory ET.f1([String v = augmented]) => ET("Augmented: $v");
augment factory ET.f2({String v = augmented}) => ET("Augmented: $v");
augment factory ET.f1([String v]) => ET("Augmented: $v");
augment factory ET.f2({String v}) => ET("Augmented: $v");
augment static String staticMethod1([String v]) => "Augmented: $v";
augment static String staticMethod2({String v}) => "Augmented: $v";
augment String instanceMethod1([String v]) => "Augmented: $v";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,348 @@
// 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 functions: Inside an augmenting function body (including
/// factory constructors but not generative constructors) `augmented` refers
/// to the augmented function. Tear-offs are not allowed, and this function
/// must immediately be invoked.
///
/// @description Checks that it is a compile-time error if a variable with the
/// name `augmented` occurs in a control-flow element in an augmenting function
/// or a factory constructor.
/// @author sgrekhov22@gmail.com

// SharedOptions=--enable-experiment=macros

var augmented = 0;

void topLevelFunction() {}

augment void topLevelFunction() {
var list = [
for (var augmented = 0; 1 > 2;) 0
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
];
var map = {
for (var i = 0; i > augmented;) i: i
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
var set = {
if (1 > augmented) 42
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
}

class C {
C();
factory C.f() => C();
static void staticMethod() {}
void instanceMethod() {}
}

augment class C {
augment factory C.f() {
var list = [
for (var augmented = 0; 1 > 2;) 0
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
];
var map = {
for (var i = 0; i > augmented;) i: i
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
var set = {
if (1 > augmented) 42
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
return C();
}

augment static void staticMethod() {
var list = [
for (var augmented = 0; 1 > 2;) 0
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
];
var map = {
for (var i = 0; i > augmented;) i: i
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
var set = {
if (1 > augmented) 42
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
}

augment void instanceMethod() {
var list = [
for (var augmented = 0; 1 > 2;) 0
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
];
var map = {
for (var i = 0; i > augmented;) i: i
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
var set = {
if (1 > augmented) 42
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
}
}

mixin M {
static void staticMethod() {}
void instanceMethod() {}
}

augment mixin M {
augment static void staticMethod() {
var list = [
for (var augmented = 0; 1 > 2;) 0
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
];
var map = {
for (var i = 0; i > augmented;) i: i
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
var set = {
if (1 > augmented) 42
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
}

augment void instanceMethod() {
var list = [
for (var augmented = 0; 1 > 2;) 0
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
];
var map = {
for (var i = 0; i > augmented;) i: i
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
var set = {
if (1 > augmented) 42
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
}
}

enum E {
e1;
static void staticMethod() {}
void instanceMethod() {}
}

augment enum E {
augment e1;
augment static void staticMethod() {
var list = [
for (var augmented = 0; 1 > 2;) 0
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
];
var map = {
for (var i = 0; i > augmented;) i: i
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
var set = {
if (1 > augmented) 42
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
}

augment void instanceMethod() {
var list = [
for (var augmented = 0; 1 > 2;) 0
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
];
var map = {
for (var i = 0; i > augmented;) i: i
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
var set = {
if (1 > augmented) 42
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
}
}

class A {}
extension Ext on A {
static void staticMethod() {}
void instanceMethod() {}
}

augment extension Ext {
augment static void staticMethod() {
var list = [
for (var augmented = 0; 1 > 2;) 0
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
];
var map = {
for (var i = 0; i > augmented;) i: i
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
var set = {
if (1 > augmented) 42
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
}

augment void instanceMethod() {
var list = [
for (var augmented = 0; 1 > 2;) 0
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
];
var map = {
for (var i = 0; i > augmented;) i: i
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
var set = {
if (1 > augmented) 42
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
}
}

extension type ET(int _) {
factory ET.f() => ET(0);
static void staticMethod() {}
void instanceMethod() {}
}

augment extension type ET {
augment factory ET.f() {
var list = [
for (var augmented = 0; 1 > 2;) 0
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
];
var map = {
for (var i = 0; i > augmented;) i: i
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
var set = {
if (1 > augmented) 42
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
return ET(0);
}

augment static void staticMethod() {
var list = [
for (var augmented = 0; 1 > 2;) 0
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
];
var map = {
for (var i = 0; i > augmented;) i: i
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
var set = {
if (1 > augmented) 42
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
}

augment void instanceMethod() {
var list = [
for (var augmented = 0; 1 > 2;) 0
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
];
var map = {
for (var i = 0; i > augmented;) i: i
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
var set = {
if (1 > augmented) 42
// ^^^^^^^^^
// [analyzer] unspecified
// [cfe] unspecified
};
}
}

main() {
print(topLevelFunction);
print(C);
print(M);
print(E);
print(A);
print(ET);
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,6 @@ augment extension type ET {

main() {
print(C);
print(E);
print(ET);
}
Loading
Loading