Skip to content

Commit

Permalink
Fixes dart-lang#3028. Add tests for mixin application constant constr…
Browse files Browse the repository at this point in the history
…uctor
  • Loading branch information
sgrekhov committed Dec 31, 2024
1 parent e07a25b commit 5184b30
Show file tree
Hide file tree
Showing 16 changed files with 644 additions and 0 deletions.
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);
}
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);
}
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
}
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);
}
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);
}
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);
}
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
}
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);
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);
}
Loading

0 comments on commit 5184b30

Please sign in to comment.