Skip to content

Commit 7b3eb67

Browse files
kallentuCommit Queue
authored andcommitted
[tests] Add more type parameter tests, add nested FutureOr and typedef tests.
Updating a few existing FutureOr and typedef tests. Adding new type parameter tests. Bug: #57038 Change-Id: Ic34b1ccbb97048d64afece6b925a3bf71d9f109e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417320 Reviewed-by: Erik Ernst <eernst@google.com> Commit-Queue: Kallen Tu <kallentu@google.com>
1 parent 9981b4a commit 7b3eb67

File tree

7 files changed

+87
-12
lines changed

7 files changed

+87
-12
lines changed

tests/language/dot_shorthands/constructor/constructor_error_test.dart

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,18 +31,6 @@ void main() {
3131
// [analyzer] unspecified
3232
// [cfe] unspecified
3333

34-
// `.new<type-args>()` and `.new<type-args>` are a compile-time error.
35-
36-
UnnamedConstructorTypeParameters typeParameters = .new<int>();
37-
// ^
38-
// [analyzer] unspecified
39-
// [cfe] unspecified
40-
41-
UnnamedConstructorTypeParameters Function() tearOff = .new<int>;
42-
// ^
43-
// [analyzer] unspecified
44-
// [cfe] unspecified
45-
4634
UnnamedConstructor Function() ctorTearoff = .new;
4735
// ^
4836
// [analyzer] unspecified

tests/language/dot_shorthands/constructor/constructor_future_or_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ void main() {
4141
const FutureOr<ConstructorClass?> constNullableCtor = .constRegular(1);
4242
const FutureOr<ConstructorClass?> constNullableCtorNamed = .constNamed(x: 1);
4343
const FutureOr<ConstructorClass?> constNullableCtorOptional = .constOptional(1);
44+
FutureOr<FutureOr<ConstructorClass>> ctorNested = .new(1);
45+
const FutureOr<FutureOr<ConstructorClass>> constCtorNested = .constRegular(1);
4446

4547
var ctorList = <FutureOr<ConstructorClass>>[.new(1), .regular(1), .optional(1), .named(x: 1)];
4648
var nullableCtorList = <FutureOr<ConstructorClass?>>[.new(1), .regular(1), .optional(1), .named(x: 1)];
@@ -65,6 +67,8 @@ void main() {
6567
const FutureOr<ConstructorExt?> constNullableCtorExt = .constRegular(1);
6668
const FutureOr<ConstructorExt?> constNullableCtorExtNamed = .constNamed(x: 1);
6769
const FutureOr<ConstructorExt?> constNullableCtorExtOptional = .constOptional(1);
70+
FutureOr<FutureOr<ConstructorExt>> ctorExtNested = .new(1);
71+
const FutureOr<FutureOr<ConstructorExt>> constCtorExtNested = .constRegular(1);
6872

6973
var ctorExtList = <FutureOr<ConstructorExt>>[.new(1), .regular(1), .optional(1), .named(x: 1)];
7074
var nullableIntegerExtList = <FutureOr<ConstructorExt?>>[.new(1), .regular(1), .optional(1), .named(x: 1)];

tests/language/dot_shorthands/member/static_method_future_or_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ class StaticMemberExtFutureOrContext {
3030
void main() {
3131
// Class
3232
FutureOr<StaticMember> member = .member();
33+
FutureOr<FutureOr<StaticMember>> memberNested = .member();
3334
FutureOr<StaticMember?> nullableMember = .memberType<String, int>("s");
3435

3536
var memberList = <FutureOr<StaticMember>>[.member(), .memberType<String, int>("s")];
@@ -41,6 +42,7 @@ void main() {
4142

4243
// Extension type
4344
FutureOr<StaticMemberExt> memberExt = .member();
45+
FutureOr<FutureOr<StaticMemberExt>> memberExtNested = .member();
4446
FutureOr<StaticMemberExt?> nullableMemberExt = .memberType<String, int>("s");
4547

4648
var memberExtList = <FutureOr<StaticMemberExt>>[.member(), .memberType<String, int>("s")];

tests/language/dot_shorthands/multiple/type_alias_test.dart

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@
77
// SharedOptions=--enable-experiment=dot-shorthands
88

99
typedef ClassAlias = A<int>;
10+
typedef AliasAlias = ClassAlias;
1011
typedef ExtensionAlias = AExt<int>;
12+
typedef ExtensionAliasAlias = ExtensionAlias;
1113

1214
class A<T> {
1315
static ClassAlias get alias => A(1);
@@ -50,4 +52,15 @@ void main() {
5052
ExtensionAlias extensionAliasCtor = .new(1).aliasGetter;
5153
ExtensionAlias extensionAliasMethod = .method();
5254
const ExtensionAlias constExtensionAlias = .constAlias;
55+
56+
// Nested typedefs
57+
AliasAlias nestedAlias = .alias;
58+
AliasAlias nestedAlias2 = .new(1).aliasGetter;
59+
AliasAlias nestedAliasMethod = .method();
60+
const AliasAlias constNestedAlias = .constAlias;
61+
62+
ExtensionAliasAlias nestedExtensionAlias = .alias;
63+
ExtensionAliasAlias nestedExtensionAliasCtor = .new(1).aliasGetter;
64+
ExtensionAliasAlias nestedExtensionAliasMethod = .method();
65+
const ExtensionAliasAlias constNestedExtensionExtensionAlias = .constAlias;
5366
}

tests/language/dot_shorthands/simple/simple_identifier_future_or_test.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ class IntegerMixinFutureOrContext {
4545
void main() {
4646
// Enum
4747
FutureOr<Color> color = .blue;
48+
FutureOr<FutureOr<Color>> colorNested = .blue;
4849
FutureOr<Color?> nullableColor = .blue;
4950
const FutureOr<Color> constColor = .blue;
5051
const FutureOr<Color?> constNullableColor = .blue;
@@ -68,6 +69,7 @@ void main() {
6869

6970
// Class
7071
FutureOr<Integer> integer = .one;
72+
FutureOr<FutureOr<Integer>> integerNested = .one;
7173
FutureOr<Integer?> nullableInteger = .one;
7274
const FutureOr<Integer> constInteger = .constOne;
7375
const FutureOr<Integer?> constNullableInteger = .constOne;
@@ -81,6 +83,7 @@ void main() {
8183

8284
// Extension type
8385
FutureOr<IntegerExt> integerExt = .one;
86+
FutureOr<FutureOr<IntegerExt>> integerExtNested = .one;
8487
FutureOr<IntegerExt?> nullableIntegerExt = .one;
8588
const FutureOr<IntegerExt> constIntegerExt = .constOne;
8689
const FutureOr<IntegerExt?> constNullableIntegerExt = .constOne;
@@ -94,6 +97,7 @@ void main() {
9497

9598
// Mixin
9699
FutureOr<IntegerMixin> integerMixin = .mixinOne;
100+
FutureOr<FutureOr<IntegerMixin>> integerMixinNested = .mixinOne;
97101
FutureOr<IntegerMixin?> nullableIntegerMixin = .mixinOne;
98102
const FutureOr<IntegerMixin> constIntegerMixin = .mixinConstOne;
99103
const FutureOr<IntegerMixin?> constNullableIntegerMixin = .mixinConstOne;
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright (c) 2025, 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+
// Errors when having the wrong type parameters and using type parameters in
6+
// `.new` or `.new()`.
7+
8+
// SharedOptions=--enable-experiment=dot-shorthands
9+
10+
import '../dot_shorthand_helper.dart';
11+
12+
void main() {
13+
StaticMember<int> s = .memberType<String, String>('s');
14+
// ^
15+
// [analyzer] unspecified
16+
// [cfe] unspecified
17+
18+
// Constructors doesn't have type parameters.
19+
StaticMember<int> constructorTypeParameter = .constNamed<int>(1);
20+
// ^
21+
// [analyzer] unspecified
22+
// [cfe] unspecified
23+
24+
// `.new<type-args>()` and `.new<type-args>` are a compile-time error.
25+
UnnamedConstructorTypeParameters typeParameters = .new<int>();
26+
// ^
27+
// [analyzer] unspecified
28+
// [cfe] unspecified
29+
30+
UnnamedConstructorTypeParameters Function() tearOff = .new<int>;
31+
// ^
32+
// [analyzer] unspecified
33+
// [cfe] unspecified
34+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// Copyright (c) 2025, 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+
// Testing `id<type>()` uses the correct type parameters.
6+
7+
// SharedOptions=--enable-experiment=dot-shorthands
8+
9+
import '../dot_shorthand_helper.dart';
10+
11+
import "package:expect/expect.dart";
12+
13+
class A<T, U> {
14+
static A<X, Y> method<X, Y>(X x, Y y) => A<X, Y>.ctor(x, y);
15+
16+
final T? x;
17+
final U? y;
18+
A.ctor(this.x, this.y);
19+
}
20+
21+
void main() {
22+
StaticMember<int> sMemberType = .memberType<int, String>(1);
23+
StaticMemberExt<int> sExtMemberType = .memberType<int, String>(1);
24+
25+
A aMethod = .method<int, int>(1, 2);
26+
Expect.type<A<int, int>>(aMethod);
27+
28+
A aCall = .method<int, int>.call(1, 2);
29+
Expect.type<A<int, int>>(aCall);
30+
}

0 commit comments

Comments
 (0)