Skip to content

Commit

Permalink
#2559. Add extension types and enums to augmenting constructors test.…
Browse files Browse the repository at this point in the history
… Part 2. (#2972)

Add extension types and enums to augmenting constructors test. Part 2.
  • Loading branch information
sgrekhov authored Nov 25, 2024
1 parent 238d3d4 commit 53a0fdc
Show file tree
Hide file tree
Showing 35 changed files with 460 additions and 112 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
/// etc).
///
/// @description Checks that it is a compile-time error if the resulting
/// constructor has a redirecting initializer and other initializers.
/// constructor has a redirecting initializer and initializer list elements.
/// @author [email protected]
// SharedOptions=--enable-experiment=macros
Expand All @@ -19,7 +19,7 @@ part 'augmenting_constructors_A06_t01_lib.dart';
class C {
int x;
C(this.x);
C.foo(): this(0);
C.foo() : this(0);
//^^^^^
// [analyzer] unspecified
// [cfe] unspecified
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
/// etc).
///
/// @description Checks that it is a compile-time error if the resulting
/// constructor has a redirecting initializer and other initializers.
/// constructor has a redirecting initializer and initializer list elements.
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

part of 'augmenting_constructors_A06_t01.dart';

augment class C {
augment C.foo(): x = 1;
augment C.foo() : x = 1;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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 It is a compile-time error if:
/// ...
/// - The resulting constructor is not valid (it has a redirection as well as
/// some initializer list elements, or it has multiple super initializers,
/// etc).
///
/// @description Checks that it is a compile-time error if the resulting
/// constructor has multiple super initializers.
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

part 'augmenting_constructors_A06_t02_lib.dart';

class A {
int x;
A(this.x);
}

class C extends A {
C() : super(0);
//^
// [analyzer] unspecified
// [cfe] unspecified
}

main() {
print(C);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// 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 It is a compile-time error if:
/// ...
/// - The resulting constructor is not valid (it has a redirection as well as
/// some initializer list elements, or it has multiple super initializers,
/// etc).
///
/// @description Checks that it is a compile-time error if the resulting
/// constructor has multiple super initializers.
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

part of 'augmenting_constructors_A06_t02.dart';

augment class C {
augment C() : super(1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion A redirecting generative constructor marked `augment` adds its
/// redirecting initializer to the augmented constructors initializer list.
/// redirection to the augmented constructor.
///
/// This converts it into a redirecting generative constructor, removing the
/// potentially non-redirecting property of the constructor.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion A redirecting generative constructor marked `augment` adds its
/// redirecting initializer to the augmented constructors initializer list.
/// redirection to the augmented constructor.
///
/// This converts it into a redirecting generative constructor, removing the
/// potentially non-redirecting property of the constructor.
Expand All @@ -18,6 +18,6 @@
part of 'augmenting_constructors_A17_t01.dart';

augment class C {
augment C.foo(int x, {int y}): this(x, y);
augment C.bar(int x, {required int y}): this.foo(x, y: y);
augment C.foo(int x, {int y}) : this(x, y);
augment C.bar(int x, {required int y}) : this.foo(x, y: y);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion A redirecting generative constructor marked `augment` adds its
/// redirecting initializer to the augmented constructors initializer list.
/// redirection to the augmented constructor.
///
/// This converts it into a redirecting generative constructor, removing the
/// potentially non-redirecting property of the constructor.
Expand All @@ -20,8 +20,8 @@ part 'augmenting_constructors_A17_t02_lib.dart';
class C {
int x;
C(this.x);
C.foo(int x): this(x + 1);
C.bar(int x): this(x + 1);
C.foo(int x) : this(x + 1);
C.bar(int x) : this(x + 1);
}

main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

/// @assertion A redirecting generative constructor marked `augment` adds its
/// redirecting initializer to the augmented constructors initializer list.
/// redirection to the augmented constructor.
///
/// This converts it into a redirecting generative constructor, removing the
/// potentially non-redirecting property of the constructor.
Expand All @@ -17,5 +17,5 @@
part of 'augmenting_constructors_A17_t02.dart';

augment class C {
augment C.bar(int x): this.foo(x + 1);
augment C.bar(int x) : this.foo(x + 1);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,21 @@ class C {
C.bar({required this.y});
}

enum E {
e0(1, 2), e1.foo(3, y: 4), e2.bar(5, y: 6);
final int x, y;
const E(this.x, [this.y = 0]);
const E.foo(this.x, {this.y = 0});
const E.bar(this.x, {required this.y});
}

extension type ET(int x) {
ET.foo(this.x);
ET.bar({required this.x});
}

main() {
print(C);
print(E);
print(ET);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,35 @@
part of 'augmenting_constructors_A18_t01.dart';

augment class C {
augment C.foo(this.x, {this.y}): this(x);
augment C.foo(this.x, {this.y}) : this(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
augment C.bar({required this.y}): this.foo(0);
augment C.bar({required this.y}) : this.foo(0);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

augment enum E {
augment e0;
augment const E.foo(this.x, {this.y}) : this(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
augment const E.bar(this.x, {required this.y}) : this.foo(0);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

augment extension type ET {
augment ET.foo(this.x) : this(0);
// ^
// [analyzer] unspecified
// [cfe] unspecified
augment ET.bar({required this.x}) : this.new(1);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,26 @@ part 'augmenting_constructors_A18_t02_lib.dart';
class C {
int x, y;
C(this.x, [this.y = 0]);
C.foo(int x, {int y = 0}): assert(x > 0);
C.bar({required int x}): x = x, y = 0;
C.foo(int x, {int y = 0}) : assert(x > 0);
C.bar({required int x}) : x = x, y = 0;
}

enum E {
e0(0);

final int x, y;
const E(this.x, [this.y = 0]);
const E.foo(int x, {int y = 0}) : assert(x > 0);
const E.bar({required int x}) : x = x, y = 0;
}

extension type ET(int x) {
ET.foo(int x) : assert(x > 0);
ET.bar({required int x}) : x = x;
}

main() {
print(C);
print(E);
print(ET);
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,35 @@
part of 'augmenting_constructors_A18_t02.dart';

augment class C {
augment C.foo(int x, {int y = 0}): this(x);
// ^
augment C.foo(int x, {int y = 0}) : this(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
augment C.bar({required int x}) : this.foo(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

augment enum E {
augment e0;
augment const E.foo(int x, {int y = 0}) : this(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
augment C.bar({required int x}): this.foo(x);
// ^
augment const E.bar({required int x}) : this.foo(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

augment extension type ET {
augment ET.foo(int x) : this(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
augment ET.bar({required int x}) : this.new(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ class A {
}

class C extends A {
C(): super(0);
C.foo(): super(0);
C() : super(0);
C.foo() : super(0);
}

main() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@
/// - The augmented constructor has an initializer list or a body, or it has a
/// redirection.
///
/// @description Checks that it is not an error to declare an augmenting
/// redirecting generative constructor more than once and the fully merged
/// constructor has no errors.
/// @description Checks that it is a compile-time error to declare an augmenting
/// redirecting generative constructor more than once.
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

import '../../Utils/expect.dart';
part 'augmenting_constructors_A18_t04_lib.dart';

class C {
Expand All @@ -24,6 +22,19 @@ class C {
C.foo(int x);
}

enum E {
e0(0), e1.foo(1);
final int x;
const E(this.x);
const E.foo(int x);
}

extension type ET(int x) {
ET.foo(int x);
}

main() {
Expect.equals(2, C.foo(1));
print(C);
print(E);
print(ET);
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,34 @@
/// redirection.
///
/// @description Checks that it is a compile-time error to declare an augmenting
/// redirecting generative constructor if the augmented constructor has a
/// non-empty initializing list.
/// redirecting generative constructor more than once.
/// @author [email protected]
// SharedOptions=--enable-experiment=macros

part of 'augmenting_constructors_A18_t04.dart';

augment class C {
augment C.foo(int x): this.foo(x); // Cyclic! But it is fixed below
augment C.foo(int x): this(x + 1); // Not a cyclic now
augment C.foo(int x) : this(x + 1); // Ok
augment C.foo(int x) : this(x + 2); // Augmented constructor already has a redirection
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

augment enum E {
augment e0;
augment const E.foo(int x) : this(x + 1);
augment const E.foo(int x) : this(x + 2);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

augment extension type ET {
augment ET.foo(int x) : this(x + 1);
augment ET.foo(int x) : this(x + 2);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ class C {
C.foo() {}
}

extension type ET(int x) {
ET.foo(int x) {}
}

main() {
print(C);
print(ET);
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,15 @@
part of 'augmenting_constructors_A18_t06.dart';

augment class C {
augment C.foo(): this();
// ^
augment C.foo() : this();
// ^
// [analyzer] unspecified
// [cfe] unspecified
}

augment extension type ET {
augment ET.foo(int x) : this(x);
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
Loading

0 comments on commit 53a0fdc

Please sign in to comment.