forked from dart-lang/co19
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes dart-lang#3028. Add tests for mixin application constant constr…
…uctor
- Loading branch information
Showing
16 changed files
with
644 additions
and
0 deletions.
There are no files selected for viewing
39 changes: 39 additions & 0 deletions
39
Language/Mixins/Mixin_Application/implicit_constructor_A01_t05.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,39 @@ | ||
// 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 each generative constructor of the form | ||
/// `Sq(T1 a1, . . ., Tk ak)` of `S` that is accessible to `LC`, `C` has an | ||
/// implicitly declared constructor of the form | ||
/// `Cq(T1 a1, ..., Tk ak): superq(a1, . . ., ak);` where `Cq` is obtained from | ||
/// `Sq` by replacing occurrences of `SN`, which denote the superclass, by `N`, | ||
/// and `superq` is obtained from `Sq` by replacing occurrences of `SN` which | ||
/// denote the superclass by super. If `Sq` is a generative const constructor, | ||
/// and `C` does not declare any instance variables, `Cq` is also a const | ||
/// constructor. | ||
/// | ||
/// @description Checks that if `Sq` is a generative const constructor, and `C` | ||
/// does not declare any instance variables then `Cq` is also a const | ||
/// constructor. | ||
/// @author [email protected] | ||
/// @issue 59796 | ||
import "../../../Utils/expect.dart"; | ||
|
||
class A { | ||
final bool v1; | ||
final num v2; | ||
const A(this.v1, this.v2); | ||
} | ||
|
||
mixin M on A { | ||
static int x = 0; | ||
} | ||
|
||
class MA = A with M; | ||
|
||
main() { | ||
MA ma = const MA(true, 2); | ||
Expect.equals(true, ma.v1); | ||
Expect.equals(2, ma.v2); | ||
} |
41 changes: 41 additions & 0 deletions
41
Language/Mixins/Mixin_Application/implicit_constructor_A01_t06.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,41 @@ | ||
// 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 each generative constructor of the form | ||
/// `Sq(T1 a1, . . ., Tk ak)` of `S` that is accessible to `LC`, `C` has an | ||
/// implicitly declared constructor of the form | ||
/// `Cq(T1 a1, ..., Tk ak): superq(a1, . . ., ak);` where `Cq` is obtained from | ||
/// `Sq` by replacing occurrences of `SN`, which denote the superclass, by `N`, | ||
/// and `superq` is obtained from `Sq` by replacing occurrences of `SN` which | ||
/// denote the superclass by super. If `Sq` is a generative const constructor, | ||
/// and `C` does not declare any instance variables, `Cq` is also a const | ||
/// constructor. | ||
/// | ||
/// @description Checks that if `Sq` is a generative const constructor, and `C` | ||
/// does not declare any instance variables then `Cq` is also a const | ||
/// constructor. | ||
/// @author [email protected] | ||
/// @issue 59796 | ||
import "../../../Utils/expect.dart"; | ||
|
||
class A { | ||
final String v1; | ||
final num v2; | ||
const A(this.v1, this.v2); | ||
} | ||
|
||
mixin M on A { | ||
static int x = 0; | ||
} | ||
|
||
class MA extends A with M { | ||
const MA(String v1, num v2) : super(v1, v2); | ||
} | ||
|
||
main() { | ||
MA ma = const MA("x", 3); | ||
Expect.equals("x", ma.v1); | ||
Expect.equals(3, ma.v2); | ||
} |
35 changes: 35 additions & 0 deletions
35
Language/Mixins/Mixin_Application/implicit_constructor_A01_t07.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,35 @@ | ||
// 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 each generative constructor of the form | ||
/// `Sq(T1 a1, . . ., Tk ak)` of `S` that is accessible to `LC`, `C` has an | ||
/// implicitly declared constructor of the form | ||
/// `Cq(T1 a1, ..., Tk ak): superq(a1, . . ., ak);` where `Cq` is obtained from | ||
/// `Sq` by replacing occurrences of `SN`, which denote the superclass, by `N`, | ||
/// and `superq` is obtained from `Sq` by replacing occurrences of `SN` which | ||
/// denote the superclass by super. If `Sq` is a generative const constructor, | ||
/// and `C` does not declare any instance variables, `Cq` is also a const | ||
/// constructor. | ||
/// | ||
/// @description Checks that if `Sq` is a generative const constructor, and `C` | ||
/// declares an instance variable then `Cq` is not a const constructor. | ||
/// @author [email protected] | ||
class A { | ||
final int a; | ||
const A(this.a); | ||
} | ||
|
||
mixin M on A { | ||
final int x = 0; | ||
} | ||
|
||
class MA = A with M; | ||
|
||
main() { | ||
MA ma = const MA(0); | ||
// ^^^^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
37 changes: 37 additions & 0 deletions
37
Language/Mixins/Mixin_Application/implicit_constructor_A01_t08.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,37 @@ | ||
// 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 each generative constructor of the form | ||
/// `Sq(T1 a1, . . ., Tk ak)` of `S` that is accessible to `LC`, `C` has an | ||
/// implicitly declared constructor of the form | ||
/// `Cq(T1 a1, ..., Tk ak): superq(a1, . . ., ak);` where `Cq` is obtained from | ||
/// `Sq` by replacing occurrences of `SN`, which denote the superclass, by `N`, | ||
/// and `superq` is obtained from `Sq` by replacing occurrences of `SN` which | ||
/// denote the superclass by super. If `Sq` is a generative const constructor, | ||
/// and `C` does not declare any instance variables, `Cq` is also a const | ||
/// constructor. | ||
/// | ||
/// @description Checks that if `Sq` is a generative const constructor, and `C` | ||
/// declares an instance variable then `Cq` is not a const constructor. | ||
/// @author [email protected] | ||
class A { | ||
final int a; | ||
const A(this.a); | ||
} | ||
|
||
mixin M on A { | ||
final int x = 0; | ||
} | ||
|
||
class MA extends A with M { | ||
const MA(int n) : super(n); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(MA); | ||
} |
44 changes: 44 additions & 0 deletions
44
Language/Mixins/Mixin_Application/implicit_constructor_A02_t03.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,44 @@ | ||
// 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 each generative constructor of the form | ||
/// `Sq(T1 a1, ..., Tk ak, [Tk+1 ak+1 = d1, ..., Tk+p ak+p = dp])` of `S` that is | ||
/// accessible to `LC`, `C` has an implicitly declared constructor of the form | ||
/// `Cq(T1 a1, ... , Tk ak, [Tk+1 ak+1 = d′1, ... , Tk+p ak+p = d′p]) : | ||
/// superq(a1, ... , ak, ak+1, ..., ap);` | ||
/// where `Cq` is obtained from `Sq` by replacing occurrences of `SN`, which | ||
/// denote the superclass, by `N`, `superq` is obtained from `Sq` by replacing | ||
/// occurrences of `SN` which denote the superclass by super, and | ||
/// `d′i, i ∈ 1..p`, is a constant expression evaluating to the same value as | ||
/// `di`. If `Sq` is a generative const constructor, and `MC` does not declare | ||
/// any instance variables, `Cq` is also a const constructor. | ||
/// | ||
/// @description Checks that if `Sq` is a generative const constructor, and `MC` | ||
/// does not declare any instance variables, `Cq` is also a const constructor. | ||
/// @author [email protected] | ||
/// @issue 59796 | ||
import "../../../Utils/expect.dart"; | ||
|
||
class A { | ||
final bool v1; | ||
final num v2; | ||
const A(bool this.v1, [num this.v2 = 3.14]); | ||
} | ||
|
||
mixin class M { | ||
static int x = 0; | ||
} | ||
|
||
class MA = A with M; | ||
|
||
main() { | ||
MA ma = const MA(true, 2); | ||
Expect.isTrue(ma.v1); | ||
Expect.equals(2, ma.v2); | ||
|
||
ma = const MA(false); | ||
Expect.isFalse(ma.v1); | ||
Expect.equals(3.14, ma.v2); | ||
} |
46 changes: 46 additions & 0 deletions
46
Language/Mixins/Mixin_Application/implicit_constructor_A02_t04.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,46 @@ | ||
// 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 each generative constructor of the form | ||
/// `Sq(T1 a1, ..., Tk ak, [Tk+1 ak+1 = d1, ..., Tk+p ak+p = dp])` of `S` that is | ||
/// accessible to `LC`, `C` has an implicitly declared constructor of the form | ||
/// `Cq(T1 a1, ... , Tk ak, [Tk+1 ak+1 = d′1, ... , Tk+p ak+p = d′p]) : | ||
/// superq(a1, ... , ak, ak+1, ..., ap);` | ||
/// where `Cq` is obtained from `Sq` by replacing occurrences of `SN`, which | ||
/// denote the superclass, by `N`, `superq` is obtained from `Sq` by replacing | ||
/// occurrences of `SN` which denote the superclass by super, and | ||
/// `d′i, i ∈ 1..p`, is a constant expression evaluating to the same value as | ||
/// `di`. If `Sq` is a generative const constructor, and `MC` does not declare | ||
/// any instance variables, `Cq` is also a const constructor. | ||
/// | ||
/// @description Checks that if `Sq` is a generative const constructor, and `MC` | ||
/// does not declare any instance variables, `Cq` is also a const constructor. | ||
/// @author [email protected] | ||
/// @issue 59796 | ||
import "../../../Utils/expect.dart"; | ||
|
||
class A { | ||
final bool v1; | ||
final num v2; | ||
const A(bool this.v1, [num this.v2 = 3.14]); | ||
} | ||
|
||
mixin class M { | ||
static int x = 0; | ||
} | ||
|
||
class MA extends A with M { | ||
const MA(bool v1, [num v2 = 0]) : super(v1, v2); | ||
} | ||
|
||
main() { | ||
MA ma = const MA(true, 2); | ||
Expect.isTrue(ma.v1); | ||
Expect.equals(2, ma.v2); | ||
|
||
ma = const MA(false); | ||
Expect.isFalse(ma.v1); | ||
Expect.equals(0, ma.v2); | ||
} |
38 changes: 38 additions & 0 deletions
38
Language/Mixins/Mixin_Application/implicit_constructor_A02_t05.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,38 @@ | ||
// 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 each generative constructor of the form | ||
/// `Sq(T1 a1, ..., Tk ak, [Tk+1 ak+1 = d1, ..., Tk+p ak+p = dp])` of `S` that is | ||
/// accessible to `LC`, `C` has an implicitly declared constructor of the form | ||
/// `Cq(T1 a1, ... , Tk ak, [Tk+1 ak+1 = d′1, ... , Tk+p ak+p = d′p]) : | ||
/// superq(a1, ... , ak, ak+1, ..., ap);` | ||
/// where `Cq` is obtained from `Sq` by replacing occurrences of `SN`, which | ||
/// denote the superclass, by `N`, `superq` is obtained from `Sq` by replacing | ||
/// occurrences of `SN` which denote the superclass by super, and | ||
/// `d′i, i ∈ 1..p`, is a constant expression evaluating to the same value as | ||
/// `di`. If `Sq` is a generative const constructor, and `MC` does not declare | ||
/// any instance variables, `Cq` is also a const constructor. | ||
/// | ||
/// @description Checks that if `Sq` is a generative const constructor, and `MC` | ||
/// declares an instance variable then `Cq` is not a const constructor. | ||
/// @author [email protected] | ||
class A { | ||
final bool v1; | ||
final num v2; | ||
const A(bool this.v1, [num this.v2 = 3.14]); | ||
} | ||
|
||
mixin class M { | ||
final int x = 1; | ||
} | ||
|
||
class MA = A with M; | ||
|
||
main() { | ||
MA ma = const MA(true, 2); | ||
// ^^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} |
39 changes: 39 additions & 0 deletions
39
Language/Mixins/Mixin_Application/implicit_constructor_A02_t06.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,39 @@ | ||
// 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 each generative constructor of the form | ||
/// `Sq(T1 a1, ..., Tk ak, [Tk+1 ak+1 = d1, ..., Tk+p ak+p = dp])` of `S` that is | ||
/// accessible to `LC`, `C` has an implicitly declared constructor of the form | ||
/// `Cq(T1 a1, ... , Tk ak, [Tk+1 ak+1 = d′1, ... , Tk+p ak+p = d′p]) : | ||
/// superq(a1, ... , ak, ak+1, ..., ap);` | ||
/// where `Cq` is obtained from `Sq` by replacing occurrences of `SN`, which | ||
/// denote the superclass, by `N`, `superq` is obtained from `Sq` by replacing | ||
/// occurrences of `SN` which denote the superclass by super, and | ||
/// `d′i, i ∈ 1..p`, is a constant expression evaluating to the same value as | ||
/// `di`. If `Sq` is a generative const constructor, and `MC` does not declare | ||
/// any instance variables, `Cq` is also a const constructor. | ||
/// | ||
/// @description Checks that if `Sq` is a generative const constructor, and `MC` | ||
/// declares an instance variable then `Cq` is not a const constructor. | ||
/// @author [email protected] | ||
class A { | ||
final bool v1; | ||
final num v2; | ||
const A(bool this.v1, [num this.v2 = 3.14]); | ||
} | ||
|
||
mixin class M { | ||
final int x = 1; | ||
} | ||
|
||
class MA extends A with M { | ||
const MA(bool this.v1, [num this.v2 = 3.14]) : super(v1, v2); | ||
// ^ | ||
// [analyzer] unspecified | ||
// [cfe] unspecified | ||
} | ||
|
||
main() { | ||
print(MA); |
44 changes: 44 additions & 0 deletions
44
Language/Mixins/Mixin_Application/implicit_constructor_A03_t06.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,44 @@ | ||
// 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 each generative constructor of the form | ||
/// `Sq(T1 a1, ..., Tk ak, {Tk+1 ak+1 = d1, ..., Tk+n ak+n = dn})` of `S` that | ||
/// is accessible to `LC`, `C` has an implicitly declared constructor of the | ||
/// form `Cq(T1 a1, ... , Tk ak, {Tk+1 ak+1 = d′1, ... , Tk+n ak+n = d′n}) | ||
/// : superq(a1, ... , ak, ak+1: ak+1, ..., ap: ap);` | ||
/// where `Cq` is obtained from `Sq` by replacing occurrences of `SN` which | ||
/// denote the superclass by `N`, `superq` is obtained from `Sq` by replacing | ||
/// occurrences of `SN` which denote the superclass by super, and | ||
/// `d′i, i ∈ 1..n`, is a constant expression evaluating to the same value as | ||
/// `di`. If `Sq` is a generative const constructor, and `M` does not declare | ||
/// any fields, `Cq` is also a const constructor. | ||
/// | ||
/// @description Checks that if `Sq` is a generative const constructor, and `M` | ||
/// does not declare any instance variables, `Cq` is also a const constructor. | ||
/// @author [email protected] | ||
/// @issue 59796 | ||
import "../../../Utils/expect.dart"; | ||
|
||
class A { | ||
final bool v1; | ||
final num v2; | ||
const A(bool this.v1, {num this.v2 = 3.14}); | ||
} | ||
|
||
mixin M { | ||
static int x = 0; | ||
} | ||
|
||
class MA = A with M; | ||
|
||
main() { | ||
MA ma = const MA(true, v2: 2); | ||
Expect.isTrue(ma.v1); | ||
Expect.equals(2, ma.v2); | ||
|
||
ma = const MA(false); | ||
Expect.isFalse(ma.v1); | ||
Expect.equals(3.14, ma.v2); | ||
} |
Oops, something went wrong.