Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 2766add

Browse files
scheglovCommit Bot
authored andcommitted
Partial fix for parsing explicitly typed super formal parameters.
I need at least this much to cover a few test cases in the analyzer, but it might be not the best implementation. It seems to not break anything, so maybe we can land this for now, while we are waiting for the better fix of the referenced issue? Bug: dart-lang/sdk#47951 Change-Id: I428e32f4435b3229cb2dc41678182cde0e2f98e8 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/226200 Reviewed-by: Chloe Stefantsova <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 80c6896 commit 2766add

File tree

10 files changed

+88
-63
lines changed

10 files changed

+88
-63
lines changed

pkg/_fe_analyzer_shared/lib/src/parser/type_info.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,18 @@ TypeInfo computeType(final Token token, bool required,
251251

252252
assert(typeParamOrArg == noTypeParamOrArg);
253253
next = next.next!;
254+
255+
// TODO(scheglov) This is a hack to partially fix.
256+
// https://github.com/dart-lang/sdk/issues/47951
257+
if (optional('?', next) &&
258+
optional('super', next.next!) &&
259+
optional('.', next.next!.next!)) {
260+
return simpleNullableType;
261+
}
262+
if (optional('super', next) && optional('.', next.next!)) {
263+
return simpleType;
264+
}
265+
254266
if (optional('.', next)) {
255267
next = next.next!;
256268
if (isValidTypeReference(next)) {

pkg/analyzer/lib/src/summary2/informative_data.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1370,6 +1370,9 @@ class _InformativeDataWriter {
13701370
} else if (notDefault is FunctionTypedFormalParameter) {
13711371
_writeTypeParameters(notDefault.typeParameters);
13721372
_writeFormalParameters(notDefault.parameters);
1373+
} else if (notDefault is SuperFormalParameter) {
1374+
_writeTypeParameters(notDefault.typeParameters);
1375+
_writeFormalParameters(notDefault.parameters);
13731376
} else {
13741377
_writeTypeParameters(null);
13751378
_writeFormalParameters(null);

pkg/analyzer/test/generated/utilities_test.dart

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,6 @@ class A {
16441644
);
16451645
}
16461646

1647-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/47951')
16481647
void test_superFormalParameter() {
16491648
var findNode = _parseStringToFindNode(r'''
16501649
class A {
@@ -1666,7 +1665,6 @@ class B extends A {
16661665
);
16671666
}
16681667

1669-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/47741')
16701668
void test_superFormalParameter_functionTyped() {
16711669
var findNode = _parseStringToFindNode(r'''
16721670
class A {

pkg/analyzer/test/src/summary/resynthesize_common.dart

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1453,7 +1453,6 @@ library
14531453
''');
14541454
}
14551455

1456-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/47951')
14571456
test_class_constructor_parameters_super_explicitType_function() async {
14581457
var library = await checkLibrary('''
14591458
class A {
@@ -1492,7 +1491,6 @@ library
14921491
''');
14931492
}
14941493

1495-
@FailingTest(issue: 'https://github.com/dart-lang/sdk/issues/47951')
14961494
test_class_constructor_parameters_super_explicitType_interface() async {
14971495
var library = await checkLibrary('''
14981496
class A {
@@ -1518,13 +1516,45 @@ library
15181516
constructors
15191517
@47
15201518
parameters
1521-
requiredPositional final super.a @49
1519+
requiredPositional final super.a @59
15221520
type: int
15231521
superConstructorParameter: a@18
15241522
superConstructor: self::@class::A::@constructor::•
15251523
''');
15261524
}
15271525

1526+
test_class_constructor_parameters_super_explicitType_interface_nullable() async {
1527+
var library = await checkLibrary('''
1528+
class A {
1529+
A(num? a);
1530+
}
1531+
1532+
class B extends A {
1533+
B(int? super.a);
1534+
}
1535+
''');
1536+
checkElementText(library, r'''
1537+
library
1538+
definingUnit
1539+
classes
1540+
class A @6
1541+
constructors
1542+
@12
1543+
parameters
1544+
requiredPositional a @19
1545+
type: num?
1546+
class B @32
1547+
supertype: A
1548+
constructors
1549+
@48
1550+
parameters
1551+
requiredPositional final super.a @61
1552+
type: int?
1553+
superConstructorParameter: a@19
1554+
superConstructor: self::@class::A::@constructor::•
1555+
''');
1556+
}
1557+
15281558
test_class_constructor_parameters_super_invalid_topFunction() async {
15291559
var library = await checkLibrary('''
15301560
void f(super.a) {}

pkg/front_end/testcases/super_parameters/default_values.dart.strong.expect

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ library /*isNonNullableByDefault*/;
22
//
33
// Problems in library:
44
//
5-
// pkg/front_end/testcases/super_parameters/default_values.dart:51:11: Error: Expected ']' before this.
5+
// pkg/front_end/testcases/super_parameters/default_values.dart:51:17: Error: The parameter 'x' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
6+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
67
// C5([int super.x]); // Error.
7-
// ^^^^^
8-
//
9-
// pkg/front_end/testcases/super_parameters/default_values.dart:61:10: Error: Expected ']' before this.
10-
// C6([int? super.x]); // Ok.
11-
// ^
8+
// ^
129
//
1310
import self as self;
1411
import "dart:core" as core;
@@ -68,8 +65,8 @@ class S5 extends core::Object {
6865
;
6966
}
7067
class C5 extends self::S5 {
71-
constructor •([dynamic int = #C4]) → self::C5
72-
: super self::S5::•()
68+
constructor •([core::int x = #C4]) → self::C5
69+
: super self::S5::•(x)
7370
;
7471
}
7572
class S6 extends core::Object {
@@ -80,8 +77,8 @@ class S6 extends core::Object {
8077
}
8178
class C6 extends self::S6 {
8279
field core::int? b = null;
83-
constructor •([dynamic int = #C4]) → self::C6
84-
: super self::S6::•()
80+
constructor •([core::int? x = #C4]) → self::C6
81+
: super self::S6::•(x)
8582
;
8683
}
8784
class S7 extends core::Object {

pkg/front_end/testcases/super_parameters/default_values.dart.strong.transformed.expect

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ library /*isNonNullableByDefault*/;
22
//
33
// Problems in library:
44
//
5-
// pkg/front_end/testcases/super_parameters/default_values.dart:51:11: Error: Expected ']' before this.
5+
// pkg/front_end/testcases/super_parameters/default_values.dart:51:17: Error: The parameter 'x' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
6+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
67
// C5([int super.x]); // Error.
7-
// ^^^^^
8-
//
9-
// pkg/front_end/testcases/super_parameters/default_values.dart:61:10: Error: Expected ']' before this.
10-
// C6([int? super.x]); // Ok.
11-
// ^
8+
// ^
129
//
1310
import self as self;
1411
import "dart:core" as core;
@@ -68,8 +65,8 @@ class S5 extends core::Object {
6865
;
6966
}
7067
class C5 extends self::S5 {
71-
constructor •([dynamic int = #C4]) → self::C5
72-
: super self::S5::•()
68+
constructor •([core::int x = #C4]) → self::C5
69+
: super self::S5::•(x)
7370
;
7471
}
7572
class S6 extends core::Object {
@@ -80,8 +77,8 @@ class S6 extends core::Object {
8077
}
8178
class C6 extends self::S6 {
8279
field core::int? b = null;
83-
constructor •([dynamic int = #C4]) → self::C6
84-
: super self::S6::•()
80+
constructor •([core::int? x = #C4]) → self::C6
81+
: super self::S6::•(x)
8582
;
8683
}
8784
class S7 extends core::Object {

pkg/front_end/testcases/super_parameters/default_values.dart.weak.expect

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ library /*isNonNullableByDefault*/;
22
//
33
// Problems in library:
44
//
5-
// pkg/front_end/testcases/super_parameters/default_values.dart:51:11: Error: Expected ']' before this.
5+
// pkg/front_end/testcases/super_parameters/default_values.dart:51:17: Error: The parameter 'x' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
6+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
67
// C5([int super.x]); // Error.
7-
// ^^^^^
8-
//
9-
// pkg/front_end/testcases/super_parameters/default_values.dart:61:10: Error: Expected ']' before this.
10-
// C6([int? super.x]); // Ok.
11-
// ^
8+
// ^
129
//
1310
import self as self;
1411
import "dart:core" as core;
@@ -68,8 +65,8 @@ class S5 extends core::Object {
6865
;
6966
}
7067
class C5 extends self::S5 {
71-
constructor •([dynamic int = #C4]) → self::C5
72-
: super self::S5::•()
68+
constructor •([core::int x = #C4]) → self::C5
69+
: super self::S5::•(x)
7370
;
7471
}
7572
class S6 extends core::Object {
@@ -80,8 +77,8 @@ class S6 extends core::Object {
8077
}
8178
class C6 extends self::S6 {
8279
field core::int? b = null;
83-
constructor •([dynamic int = #C4]) → self::C6
84-
: super self::S6::•()
80+
constructor •([core::int? x = #C4]) → self::C6
81+
: super self::S6::•(x)
8582
;
8683
}
8784
class S7 extends core::Object {

pkg/front_end/testcases/super_parameters/default_values.dart.weak.modular.expect

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ library /*isNonNullableByDefault*/;
22
//
33
// Problems in library:
44
//
5-
// pkg/front_end/testcases/super_parameters/default_values.dart:51:11: Error: Expected ']' before this.
5+
// pkg/front_end/testcases/super_parameters/default_values.dart:51:17: Error: The parameter 'x' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
6+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
67
// C5([int super.x]); // Error.
7-
// ^^^^^
8-
//
9-
// pkg/front_end/testcases/super_parameters/default_values.dart:61:10: Error: Expected ']' before this.
10-
// C6([int? super.x]); // Ok.
11-
// ^
8+
// ^
129
//
1310
import self as self;
1411
import "dart:core" as core;
@@ -68,8 +65,8 @@ class S5 extends core::Object {
6865
;
6966
}
7067
class C5 extends self::S5 {
71-
constructor •([dynamic int = #C4]) → self::C5
72-
: super self::S5::•()
68+
constructor •([core::int x = #C4]) → self::C5
69+
: super self::S5::•(x)
7370
;
7471
}
7572
class S6 extends core::Object {
@@ -80,8 +77,8 @@ class S6 extends core::Object {
8077
}
8178
class C6 extends self::S6 {
8279
field core::int? b = null;
83-
constructor •([dynamic int = #C4]) → self::C6
84-
: super self::S6::•()
80+
constructor •([core::int? x = #C4]) → self::C6
81+
: super self::S6::•(x)
8582
;
8683
}
8784
class S7 extends core::Object {

pkg/front_end/testcases/super_parameters/default_values.dart.weak.outline.expect

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ library /*isNonNullableByDefault*/;
22
//
33
// Problems in library:
44
//
5-
// pkg/front_end/testcases/super_parameters/default_values.dart:51:11: Error: Expected ']' before this.
5+
// pkg/front_end/testcases/super_parameters/default_values.dart:51:17: Error: The parameter 'x' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
6+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
67
// C5([int super.x]); // Error.
7-
// ^^^^^
8-
//
9-
// pkg/front_end/testcases/super_parameters/default_values.dart:61:10: Error: Expected ']' before this.
10-
// C6([int? super.x]); // Ok.
11-
// ^
8+
// ^
129
//
1310
import self as self;
1411
import "dart:core" as core;
@@ -59,7 +56,7 @@ class S5 extends core::Object {
5956
;
6057
}
6158
class C5 extends self::S5 {
62-
constructor •([dynamic int]) → self::C5
59+
constructor •([core::int x]) → self::C5
6360
;
6461
}
6562
class S6 extends core::Object {
@@ -69,7 +66,7 @@ class S6 extends core::Object {
6966
}
7067
class C6 extends self::S6 {
7168
field core::int? b;
72-
constructor •([dynamic int]) → self::C6
69+
constructor •([core::int? x]) → self::C6
7370
;
7471
}
7572
class S7 extends core::Object {

pkg/front_end/testcases/super_parameters/default_values.dart.weak.transformed.expect

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,10 @@ library /*isNonNullableByDefault*/;
22
//
33
// Problems in library:
44
//
5-
// pkg/front_end/testcases/super_parameters/default_values.dart:51:11: Error: Expected ']' before this.
5+
// pkg/front_end/testcases/super_parameters/default_values.dart:51:17: Error: The parameter 'x' can't have a value of 'null' because of its type 'int', but the implicit default value is 'null'.
6+
// Try adding either an explicit non-'null' default value or the 'required' modifier.
67
// C5([int super.x]); // Error.
7-
// ^^^^^
8-
//
9-
// pkg/front_end/testcases/super_parameters/default_values.dart:61:10: Error: Expected ']' before this.
10-
// C6([int? super.x]); // Ok.
11-
// ^
8+
// ^
129
//
1310
import self as self;
1411
import "dart:core" as core;
@@ -68,8 +65,8 @@ class S5 extends core::Object {
6865
;
6966
}
7067
class C5 extends self::S5 {
71-
constructor •([dynamic int = #C4]) → self::C5
72-
: super self::S5::•()
68+
constructor •([core::int x = #C4]) → self::C5
69+
: super self::S5::•(x)
7370
;
7471
}
7572
class S6 extends core::Object {
@@ -80,8 +77,8 @@ class S6 extends core::Object {
8077
}
8178
class C6 extends self::S6 {
8279
field core::int? b = null;
83-
constructor •([dynamic int = #C4]) → self::C6
84-
: super self::S6::•()
80+
constructor •([core::int? x = #C4]) → self::C6
81+
: super self::S6::•(x)
8582
;
8683
}
8784
class S7 extends core::Object {

0 commit comments

Comments
 (0)