You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[cfe] Disallow '.new<int>' and type parameters on constructors for dot shorthands.
Adds errors for this part of the spec behaviour: `.new<typeArgs> and .new<typeArgs>(args) will always be compile-time errors because .new denotes a constructor which is not generic`
Bug: #59758
Change-Id: I76074d2314f40f60015324d4b01ece7477a8ffb4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/417880
Reviewed-by: Johnni Winther <[email protected]>
Commit-Queue: Kallen Tu <[email protected]>
// pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:11:23: Error: A dot shorthand constructor invocation can't have type arguments.
6
+
// Try adding the class name and type arguments explicitly before the constructor name.
7
+
// C newConstructor = .new<int>();
8
+
// ^^^
9
+
//
10
+
// pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:12:25: Error: A dot shorthand constructor invocation can't have type arguments.
11
+
// Try adding the class name and type arguments explicitly before the constructor name.
12
+
// C namedConstructor = .named<int>();
13
+
// ^^^^^
14
+
//
15
+
// pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:13:19: Error: The static getter or field 'new' isn't defined for the type 'C'.
16
+
// - 'C' is from 'pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart'.
17
+
// Try correcting the name to the name of an existing static getter or field, or defining a getter or field named 'new'.
18
+
// C newTearoff = .new<int>;
19
+
// ^^^
20
+
//
21
+
// pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:13:22: Error: The static type of the explicit instantiation operand must be a generic function type but is 'dynamic'.
22
+
// Try changing the operand or remove the type arguments.
23
+
// C newTearoff = .new<int>;
24
+
// ^
25
+
//
26
+
import self as self;
27
+
import "dart:core" as core;
28
+
29
+
class C extends core::Object {
30
+
constructor •() → self::C
31
+
: super core::Object::•()
32
+
;
33
+
constructor named() → self::C
34
+
: super core::Object::•()
35
+
;
36
+
}
37
+
static method test() → void {
38
+
self::C newConstructor = invalid-expression "pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:11:23: Error: A dot shorthand constructor invocation can't have type arguments.
39
+
Try adding the class name and type arguments explicitly before the constructor name.
40
+
C newConstructor = .new<int>();
41
+
^^^" as{TypeError,ForDynamic} self::C;
42
+
self::C namedConstructor = invalid-expression "pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:12:25: Error: A dot shorthand constructor invocation can't have type arguments.
43
+
Try adding the class name and type arguments explicitly before the constructor name.
44
+
C namedConstructor = .named<int>();
45
+
^^^^^" as{TypeError,ForDynamic} self::C;
46
+
self::C newTearoff = invalid-expression "pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:13:22: Error: The static type of the explicit instantiation operand must be a generic function type but is 'dynamic'.
47
+
Try changing the operand or remove the type arguments.
// pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:11:23: Error: A dot shorthand constructor invocation can't have type arguments.
6
+
// Try adding the class name and type arguments explicitly before the constructor name.
7
+
// C newConstructor = .new<int>();
8
+
// ^^^
9
+
//
10
+
// pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:12:25: Error: A dot shorthand constructor invocation can't have type arguments.
11
+
// Try adding the class name and type arguments explicitly before the constructor name.
12
+
// C namedConstructor = .named<int>();
13
+
// ^^^^^
14
+
//
15
+
// pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:13:19: Error: The static getter or field 'new' isn't defined for the type 'C'.
16
+
// - 'C' is from 'pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart'.
17
+
// Try correcting the name to the name of an existing static getter or field, or defining a getter or field named 'new'.
18
+
// C newTearoff = .new<int>;
19
+
// ^^^
20
+
//
21
+
// pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:13:22: Error: The static type of the explicit instantiation operand must be a generic function type but is 'dynamic'.
22
+
// Try changing the operand or remove the type arguments.
23
+
// C newTearoff = .new<int>;
24
+
// ^
25
+
//
26
+
import self as self;
27
+
import "dart:core" as core;
28
+
29
+
class C extends core::Object {
30
+
constructor •() → self::C
31
+
: super core::Object::•()
32
+
;
33
+
constructor named() → self::C
34
+
: super core::Object::•()
35
+
;
36
+
}
37
+
static method test() → void {
38
+
self::C newConstructor = invalid-expression "pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:11:23: Error: A dot shorthand constructor invocation can't have type arguments.
39
+
Try adding the class name and type arguments explicitly before the constructor name.
40
+
C newConstructor = .new<int>();
41
+
^^^" as{TypeError,ForDynamic} self::C;
42
+
self::C namedConstructor = invalid-expression "pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:12:25: Error: A dot shorthand constructor invocation can't have type arguments.
43
+
Try adding the class name and type arguments explicitly before the constructor name.
44
+
C namedConstructor = .named<int>();
45
+
^^^^^" as{TypeError,ForDynamic} self::C;
46
+
self::C newTearoff = invalid-expression "pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:13:22: Error: The static type of the explicit instantiation operand must be a generic function type but is 'dynamic'.
47
+
Try changing the operand or remove the type arguments.
// pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:11:23: Error: A dot shorthand constructor invocation can't have type arguments.
6
+
// Try adding the class name and type arguments explicitly before the constructor name.
7
+
// C newConstructor = .new<int>();
8
+
// ^^^
9
+
//
10
+
// pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:12:25: Error: A dot shorthand constructor invocation can't have type arguments.
11
+
// Try adding the class name and type arguments explicitly before the constructor name.
12
+
// C namedConstructor = .named<int>();
13
+
// ^^^^^
14
+
//
15
+
// pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:13:19: Error: The static getter or field 'new' isn't defined for the type 'C'.
16
+
// - 'C' is from 'pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart'.
17
+
// Try correcting the name to the name of an existing static getter or field, or defining a getter or field named 'new'.
18
+
// C newTearoff = .new<int>;
19
+
// ^^^
20
+
//
21
+
// pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:13:22: Error: The static type of the explicit instantiation operand must be a generic function type but is 'dynamic'.
22
+
// Try changing the operand or remove the type arguments.
23
+
// C newTearoff = .new<int>;
24
+
// ^
25
+
//
26
+
import self as self;
27
+
import "dart:core" as core;
28
+
29
+
class C extends core::Object {
30
+
constructor •() → self::C
31
+
: super core::Object::•()
32
+
;
33
+
constructor named() → self::C
34
+
: super core::Object::•()
35
+
;
36
+
}
37
+
static method test() → void {
38
+
self::C newConstructor = invalid-expression "pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:11:23: Error: A dot shorthand constructor invocation can't have type arguments.
39
+
Try adding the class name and type arguments explicitly before the constructor name.
40
+
C newConstructor = .new<int>();
41
+
^^^" as{TypeError,ForDynamic,Unchecked} self::C;
42
+
self::C namedConstructor = invalid-expression "pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:12:25: Error: A dot shorthand constructor invocation can't have type arguments.
43
+
Try adding the class name and type arguments explicitly before the constructor name.
self::C newTearoff = invalid-expression "pkg/front_end/testcases/dot_shorthands/constructor_type_parameter_error.dart:13:22: Error: The static type of the explicit instantiation operand must be a generic function type but is 'dynamic'.
47
+
Try changing the operand or remove the type arguments.
0 commit comments