Skip to content

Commit d365c9f

Browse files
author
sgrekhov
committed
#1231. More Super parameters tests added
1 parent c046711 commit d365c9f

File tree

8 files changed

+256
-0
lines changed

8 files changed

+256
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Effectively, each super parameters, super.p:
6+
/// ...
7+
/// Implicitly infers its type and default value, if not specified, if
8+
/// applicable, from the associated super-constructor parameter that they are
9+
/// forwarded to.
10+
///
11+
/// @description Check that super parameter implicitly infers its type from the
12+
/// associated super-constructor parameter that they are forwarded to.
13+
/// @author [email protected]
14+
15+
// SharedOptions=--enable-experiment=super-parameters
16+
17+
import "../../Utils/expect.dart";
18+
19+
class S {
20+
num s;
21+
S([this.s = 3.14]);
22+
}
23+
24+
class C extends S {
25+
int c;
26+
C(this.c, [super.s, int x]);
27+
}
28+
29+
main() {
30+
Expect.equals(3.14, C(1).s);
31+
}
32+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Effectively, each super parameters, super.p:
6+
/// ...
7+
/// Implicitly infers its type and default value, if not specified, if
8+
/// applicable, from the associated super-constructor parameter that they are
9+
/// forwarded to.
10+
///
11+
/// @description Check that super parameter implicitly infers its type from the
12+
/// associated super-constructor parameter that they are forwarded to.
13+
/// @author [email protected]
14+
15+
// SharedOptions=--enable-experiment=super-parameters
16+
17+
import "../../Utils/expect.dart";
18+
19+
class S {
20+
num s;
21+
S([num n = 3.14]) : s = n + 1;
22+
}
23+
24+
class C extends S {
25+
int c;
26+
C(this.c, [super.s, int x]);
27+
}
28+
29+
main() {
30+
Expect.equals(4.14, C(1).s);
31+
}
32+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Effectively, each super parameters, super.p:
6+
/// ...
7+
/// Implicitly infers its type and default value, if not specified, if
8+
/// applicable, from the associated super-constructor parameter that they are
9+
/// forwarded to.
10+
///
11+
/// @description Check that super parameter implicitly infers its type from the
12+
/// associated super-constructor parameter that they are forwarded to.
13+
/// @author [email protected]
14+
15+
// SharedOptions=--enable-experiment=super-parameters
16+
17+
import "../../Utils/expect.dart";
18+
19+
class S {
20+
num s;
21+
S({this.s = 3.14});
22+
}
23+
24+
class C extends S {
25+
int c;
26+
C(this.c, {super.s, int x});
27+
}
28+
29+
main() {
30+
Expect.equals(3.14, C(1).s);
31+
}
32+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Effectively, each super parameters, super.p:
6+
/// ...
7+
/// Implicitly infers its type and default value, if not specified, if
8+
/// applicable, from the associated super-constructor parameter that they are
9+
/// forwarded to.
10+
///
11+
/// @description Check that super parameter implicitly infers its type from the
12+
/// associated super-constructor parameter that they are forwarded to.
13+
/// @author [email protected]
14+
15+
// SharedOptions=--enable-experiment=super-parameters
16+
17+
import "../../Utils/expect.dart";
18+
19+
class S {
20+
num s;
21+
S({num n = 3.14}) : s = n + 1;
22+
}
23+
24+
class C extends S {
25+
int c;
26+
C(this.c, {super.s, int x});
27+
}
28+
29+
main() {
30+
Expect.equals(4.14, C(1).s);
31+
}
32+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Effectively, each super parameters, super.p:
6+
/// ...
7+
/// Cannot be positional if the super-constructor invocation already has
8+
/// positional arguments.
9+
///
10+
/// @description Check that super parameter сannot be positional if the
11+
/// super-constructor invocation already has positional arguments.
12+
/// @author [email protected]
13+
14+
// SharedOptions=--enable-experiment=super-parameters
15+
16+
class S {
17+
num s1, s2;
18+
S(this.s1, [this.s2 = 3.14]);
19+
}
20+
21+
class C extends S {
22+
int c;
23+
C(int x, super.s2) : this.c = x + 1, super(42);
24+
// ^^^^^^^^
25+
// [analyzer] unspecified
26+
// [cfe] unspecified
27+
}
28+
29+
main() {
30+
C(1, 2);
31+
}
32+
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Effectively, each super parameters, super.p:
6+
/// ...
7+
/// Cannot be positional if the super-constructor invocation already has
8+
/// positional arguments.
9+
///
10+
/// @description Check that super parameter сannot be positional if the
11+
/// super-constructor invocation already has positional arguments.
12+
/// @author [email protected]
13+
14+
// SharedOptions=--enable-experiment=super-parameters
15+
16+
class S {
17+
num s1, s2, s3;
18+
S(this.s1, int x, {this.s3 = 3.14});
19+
}
20+
21+
class C extends S {
22+
int c;
23+
C(this.c, super.s2) : super. super(42, s3: 0);
24+
// ^^^^^^^^
25+
// [analyzer] unspecified
26+
// [cfe] unspecified
27+
}
28+
29+
main() {
30+
C(1, 2);
31+
}
32+
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Effectively, each super parameters, super.p:
6+
/// ...
7+
/// But can always be named.
8+
///
9+
/// @description Check that super parameter always can be named
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=super-parameters
13+
14+
import "../../Utils/expect.dart";
15+
16+
class S {
17+
num s1, s2;
18+
S(this.s1, {this.s2 = 3.14});
19+
}
20+
21+
class C extends S {
22+
int c;
23+
C(int x, {super.s2}) : this.c = x + 1, super(42);
24+
}
25+
26+
main() {
27+
var c = C(1, s2: -1);
28+
Expect.equals(-1, c.s2);
29+
Expect.equals(42, c.s1);
30+
}
31+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) 2021, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
5+
/// @assertion Effectively, each super parameters, super.p:
6+
/// ...
7+
/// But can always be named.
8+
///
9+
/// @description Check that super parameter always can be named
10+
/// @author [email protected]
11+
12+
// SharedOptions=--enable-experiment=super-parameters
13+
14+
import "../../Utils/expect.dart";
15+
16+
class S {
17+
num s1, s2, s3, s4;
18+
S(this.s1, num x, {this.s3 = 3.14, this.s4 = 0}) : this.s2 = x;
19+
}
20+
21+
class C extends S {
22+
int c;
23+
C(int x, {super.s3, super.s4}) : this.c = x + 1, super(42, -1);
24+
}
25+
26+
main() {
27+
var c = C(1, s3: -3, s4: 4);
28+
Expect.equals(42, c.s1);
29+
Expect.equals(-1, c.s2);
30+
Expect.equals(-3, c.s3);
31+
Expect.equals(4, c.s3);
32+
}
33+

0 commit comments

Comments
 (0)