Skip to content

Commit 25f6d99

Browse files
chloestefantsovaosa1
authored andcommitted
[cfe] Separate inference and error reporting in super parameters of extension type constructors
This is a follow-up to https://dart-review.googlesource.com/c/sdk/+/331048/comment/fbe89f66_bcf80d94/ Part of dart-lang#49731 Change-Id: I989cc3d3031e0bc4e66be1e28454443f918d20e4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333003 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent 917ef19 commit 25f6d99

11 files changed

+133
-9
lines changed

pkg/front_end/lib/src/fasta/source/outline_builder.dart

+17-3
Original file line numberDiff line numberDiff line change
@@ -2816,15 +2816,29 @@ class OutlineBuilder extends StackListenerImpl {
28162816
}
28172817
}
28182818
}
2819-
if (formals == null &&
2820-
declarationContext == DeclarationContext.ExtensionType &&
2821-
kind == MemberKind.PrimaryConstructor) {
2819+
if (declarationContext == DeclarationContext.ExtensionType &&
2820+
kind == MemberKind.PrimaryConstructor &&
2821+
formals == null) {
28222822
// In case of primary constructors of extension types, an error is
28232823
// reported by the parser if the formals together with the parentheses
28242824
// around them are missing. To distinguish that case from the case of the
28252825
// formal parameters present, but lacking the representation field, we
28262826
// pass the empty list further along instead of `null`.
28272827
formals = const [];
2828+
} else if ((declarationContext == DeclarationContext.ExtensionType &&
2829+
kind == MemberKind.PrimaryConstructor ||
2830+
declarationContext ==
2831+
DeclarationContext.ExtensionTypeConstructor) &&
2832+
formals != null) {
2833+
for (FormalParameterBuilder formal in formals) {
2834+
if (formal.isSuperInitializingFormal) {
2835+
libraryBuilder.addProblem(
2836+
messageExtensionTypeConstructorWithSuperFormalParameter,
2837+
formal.charOffset,
2838+
formal.name.length,
2839+
formal.fileUri);
2840+
}
2841+
}
28282842
}
28292843
push(beginToken.charOffset);
28302844
push(formals ?? NullValues.FormalParameters);

pkg/front_end/lib/src/fasta/source/source_constructor_builder.dart

-6
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import '../messages.dart'
3535
show
3636
LocatedMessage,
3737
Message,
38-
messageExtensionTypeConstructorWithSuperFormalParameter,
3938
messageMoreThanOneSuperInitializer,
4039
messageRedirectingConstructorWithAnotherInitializer,
4140
messageRedirectingConstructorWithMultipleRedirectInitializers,
@@ -1176,11 +1175,6 @@ class SourceExtensionTypeConstructorBuilder
11761175
if (formal.isSuperInitializingFormal) {
11771176
TypeBuilder formalTypeBuilder = formal.type;
11781177
if (formalTypeBuilder is InferableTypeBuilder) {
1179-
libraryBuilder.addProblem(
1180-
messageExtensionTypeConstructorWithSuperFormalParameter,
1181-
formal.charOffset,
1182-
formal.name.length,
1183-
formal.fileUri);
11841178
formalTypeBuilder.registerType(const InvalidType());
11851179
}
11861180
}

pkg/front_end/testcases/extension_types/issue53212.dart

+2
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,5 @@ extension type E2(int foo) {
1313
extension type E3(int foo) {
1414
E3.named(this.foo, [super.bar = null]);
1515
}
16+
17+
extension type E4(super.foo) {} // Error.

pkg/front_end/testcases/extension_types/issue53212.dart.strong.expect

+19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ library;
1414
// E3.named(this.foo, [super.bar = null]);
1515
// ^^^
1616
//
17+
// pkg/front_end/testcases/extension_types/issue53212.dart:17:25: Error: Extension type constructors can't declare super formal parameters.
18+
// extension type E4(super.foo) {} // Error.
19+
// ^^^
20+
//
21+
// pkg/front_end/testcases/extension_types/issue53212.dart:17:25: Error: Expected a representation type.
22+
// extension type E4(super.foo) {} // Error.
23+
// ^^^
24+
//
1725
import self as self;
1826
import "dart:core" as core;
1927

@@ -38,6 +46,11 @@ extension type E3(core::int foo) {
3846
constructor named = self::E3|constructor#named;
3947
constructor tearoff named = self::E3|constructor#_#named#tearOff;
4048
}
49+
extension type E4(dynamic foo) {
50+
abstract inline-class-member representation-field get foo() → dynamic;
51+
constructor • = self::E4|constructor#;
52+
constructor tearoff • = self::E4|constructor#_#new#tearOff;
53+
}
4154
static inline-class-member method E1|constructor#(core::int foo) → self::E1 /* = core::int */ {
4255
lowered final self::E1 /* = core::int */ #this = foo;
4356
return #this;
@@ -74,6 +87,12 @@ static inline-class-member method E3|constructor#named(core::int foo, [has-decla
7487
}
7588
static inline-class-member method E3|constructor#_#named#tearOff(core::int foo, [has-declared-initializer invalid-type bar]) → self::E3 /* = core::int */
7689
return self::E3|constructor#named(foo, bar);
90+
static inline-class-member method E4|constructor#(dynamic foo) → self::E4 /* = dynamic */ {
91+
lowered final self::E4 /* = dynamic */ #this = foo;
92+
return #this;
93+
}
94+
static inline-class-member method E4|constructor#_#new#tearOff(dynamic foo) → self::E4 /* = dynamic */
95+
return self::E4|constructor#(foo);
7796

7897
constants {
7998
#C1 = null

pkg/front_end/testcases/extension_types/issue53212.dart.strong.transformed.expect

+19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ library;
1414
// E3.named(this.foo, [super.bar = null]);
1515
// ^^^
1616
//
17+
// pkg/front_end/testcases/extension_types/issue53212.dart:17:25: Error: Extension type constructors can't declare super formal parameters.
18+
// extension type E4(super.foo) {} // Error.
19+
// ^^^
20+
//
21+
// pkg/front_end/testcases/extension_types/issue53212.dart:17:25: Error: Expected a representation type.
22+
// extension type E4(super.foo) {} // Error.
23+
// ^^^
24+
//
1725
import self as self;
1826
import "dart:core" as core;
1927

@@ -38,6 +46,11 @@ extension type E3(core::int foo) {
3846
constructor named = self::E3|constructor#named;
3947
constructor tearoff named = self::E3|constructor#_#named#tearOff;
4048
}
49+
extension type E4(dynamic foo) {
50+
abstract inline-class-member representation-field get foo() → dynamic;
51+
constructor • = self::E4|constructor#;
52+
constructor tearoff • = self::E4|constructor#_#new#tearOff;
53+
}
4154
static inline-class-member method E1|constructor#(core::int foo) → self::E1 /* = core::int */ {
4255
lowered final self::E1 /* = core::int */ #this = foo;
4356
return #this;
@@ -74,6 +87,12 @@ static inline-class-member method E3|constructor#named(core::int foo, [has-decla
7487
}
7588
static inline-class-member method E3|constructor#_#named#tearOff(core::int foo, [has-declared-initializer invalid-type bar]) → self::E3 /* = core::int */
7689
return self::E3|constructor#named(foo, bar);
90+
static inline-class-member method E4|constructor#(dynamic foo) → self::E4 /* = dynamic */ {
91+
lowered final self::E4 /* = dynamic */ #this = foo;
92+
return #this;
93+
}
94+
static inline-class-member method E4|constructor#_#new#tearOff(dynamic foo) → self::E4 /* = dynamic */
95+
return self::E4|constructor#(foo);
7796

7897
constants {
7998
#C1 = null

pkg/front_end/testcases/extension_types/issue53212.dart.textual_outline.expect

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ extension type E2(int foo) {
77
extension type E3(int foo) {
88
E3.named(this.foo, [super.bar = null]);
99
}
10+
extension type E4(super.foo) {}

pkg/front_end/testcases/extension_types/issue53212.dart.textual_outline_modelled.expect

+1
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ extension type E2(int foo) {
77
extension type E3(int foo) {
88
E3.named(this.foo, [super.bar = null]);
99
}
10+
extension type E4(super.foo) {}

pkg/front_end/testcases/extension_types/issue53212.dart.weak.expect

+19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ library;
1414
// E3.named(this.foo, [super.bar = null]);
1515
// ^^^
1616
//
17+
// pkg/front_end/testcases/extension_types/issue53212.dart:17:25: Error: Extension type constructors can't declare super formal parameters.
18+
// extension type E4(super.foo) {} // Error.
19+
// ^^^
20+
//
21+
// pkg/front_end/testcases/extension_types/issue53212.dart:17:25: Error: Expected a representation type.
22+
// extension type E4(super.foo) {} // Error.
23+
// ^^^
24+
//
1725
import self as self;
1826
import "dart:core" as core;
1927

@@ -38,6 +46,11 @@ extension type E3(core::int foo) {
3846
constructor named = self::E3|constructor#named;
3947
constructor tearoff named = self::E3|constructor#_#named#tearOff;
4048
}
49+
extension type E4(dynamic foo) {
50+
abstract inline-class-member representation-field get foo() → dynamic;
51+
constructor • = self::E4|constructor#;
52+
constructor tearoff • = self::E4|constructor#_#new#tearOff;
53+
}
4154
static inline-class-member method E1|constructor#(core::int foo) → self::E1 /* = core::int */ {
4255
lowered final self::E1 /* = core::int */ #this = foo;
4356
return #this;
@@ -74,6 +87,12 @@ static inline-class-member method E3|constructor#named(core::int foo, [has-decla
7487
}
7588
static inline-class-member method E3|constructor#_#named#tearOff(core::int foo, [has-declared-initializer invalid-type bar]) → self::E3 /* = core::int */
7689
return self::E3|constructor#named(foo, bar);
90+
static inline-class-member method E4|constructor#(dynamic foo) → self::E4 /* = dynamic */ {
91+
lowered final self::E4 /* = dynamic */ #this = foo;
92+
return #this;
93+
}
94+
static inline-class-member method E4|constructor#_#new#tearOff(dynamic foo) → self::E4 /* = dynamic */
95+
return self::E4|constructor#(foo);
7796

7897
constants {
7998
#C1 = null

pkg/front_end/testcases/extension_types/issue53212.dart.weak.modular.expect

+19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ library;
1414
// E3.named(this.foo, [super.bar = null]);
1515
// ^^^
1616
//
17+
// pkg/front_end/testcases/extension_types/issue53212.dart:17:25: Error: Extension type constructors can't declare super formal parameters.
18+
// extension type E4(super.foo) {} // Error.
19+
// ^^^
20+
//
21+
// pkg/front_end/testcases/extension_types/issue53212.dart:17:25: Error: Expected a representation type.
22+
// extension type E4(super.foo) {} // Error.
23+
// ^^^
24+
//
1725
import self as self;
1826
import "dart:core" as core;
1927

@@ -38,6 +46,11 @@ extension type E3(core::int foo) {
3846
constructor named = self::E3|constructor#named;
3947
constructor tearoff named = self::E3|constructor#_#named#tearOff;
4048
}
49+
extension type E4(dynamic foo) {
50+
abstract inline-class-member representation-field get foo() → dynamic;
51+
constructor • = self::E4|constructor#;
52+
constructor tearoff • = self::E4|constructor#_#new#tearOff;
53+
}
4154
static inline-class-member method E1|constructor#(core::int foo) → self::E1 /* = core::int */ {
4255
lowered final self::E1 /* = core::int */ #this = foo;
4356
return #this;
@@ -74,6 +87,12 @@ static inline-class-member method E3|constructor#named(core::int foo, [has-decla
7487
}
7588
static inline-class-member method E3|constructor#_#named#tearOff(core::int foo, [has-declared-initializer invalid-type bar]) → self::E3 /* = core::int */
7689
return self::E3|constructor#named(foo, bar);
90+
static inline-class-member method E4|constructor#(dynamic foo) → self::E4 /* = dynamic */ {
91+
lowered final self::E4 /* = dynamic */ #this = foo;
92+
return #this;
93+
}
94+
static inline-class-member method E4|constructor#_#new#tearOff(dynamic foo) → self::E4 /* = dynamic */
95+
return self::E4|constructor#(foo);
7796

7897
constants {
7998
#C1 = null

pkg/front_end/testcases/extension_types/issue53212.dart.weak.outline.expect

+17
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ library;
1414
// E3.named(this.foo, [super.bar = null]);
1515
// ^^^
1616
//
17+
// pkg/front_end/testcases/extension_types/issue53212.dart:17:25: Error: Extension type constructors can't declare super formal parameters.
18+
// extension type E4(super.foo) {} // Error.
19+
// ^^^
20+
//
21+
// pkg/front_end/testcases/extension_types/issue53212.dart:17:25: Error: Expected a representation type.
22+
// extension type E4(super.foo) {} // Error.
23+
// ^^^
24+
//
1725
import self as self;
1826
import "dart:core" as core;
1927

@@ -38,6 +46,11 @@ extension type E3(core::int foo) {
3846
constructor named = self::E3|constructor#named;
3947
constructor tearoff named = self::E3|constructor#_#named#tearOff;
4048
}
49+
extension type E4(dynamic foo) {
50+
abstract inline-class-member representation-field get foo() → dynamic;
51+
constructor • = self::E4|constructor#;
52+
constructor tearoff • = self::E4|constructor#_#new#tearOff;
53+
}
4154
static inline-class-member method E1|constructor#(core::int foo) → self::E1 /* = core::int */
4255
;
4356
static inline-class-member method E1|constructor#_#new#tearOff(core::int foo) → self::E1 /* = core::int */
@@ -62,3 +75,7 @@ static inline-class-member method E3|constructor#named(core::int foo, [has-decla
6275
;
6376
static inline-class-member method E3|constructor#_#named#tearOff(core::int foo, [has-declared-initializer invalid-type bar]) → self::E3 /* = core::int */
6477
return self::E3|constructor#named(foo, bar);
78+
static inline-class-member method E4|constructor#(dynamic foo) → self::E4 /* = dynamic */
79+
;
80+
static inline-class-member method E4|constructor#_#new#tearOff(dynamic foo) → self::E4 /* = dynamic */
81+
return self::E4|constructor#(foo);

pkg/front_end/testcases/extension_types/issue53212.dart.weak.transformed.expect

+19
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ library;
1414
// E3.named(this.foo, [super.bar = null]);
1515
// ^^^
1616
//
17+
// pkg/front_end/testcases/extension_types/issue53212.dart:17:25: Error: Extension type constructors can't declare super formal parameters.
18+
// extension type E4(super.foo) {} // Error.
19+
// ^^^
20+
//
21+
// pkg/front_end/testcases/extension_types/issue53212.dart:17:25: Error: Expected a representation type.
22+
// extension type E4(super.foo) {} // Error.
23+
// ^^^
24+
//
1725
import self as self;
1826
import "dart:core" as core;
1927

@@ -38,6 +46,11 @@ extension type E3(core::int foo) {
3846
constructor named = self::E3|constructor#named;
3947
constructor tearoff named = self::E3|constructor#_#named#tearOff;
4048
}
49+
extension type E4(dynamic foo) {
50+
abstract inline-class-member representation-field get foo() → dynamic;
51+
constructor • = self::E4|constructor#;
52+
constructor tearoff • = self::E4|constructor#_#new#tearOff;
53+
}
4154
static inline-class-member method E1|constructor#(core::int foo) → self::E1 /* = core::int */ {
4255
lowered final self::E1 /* = core::int */ #this = foo;
4356
return #this;
@@ -74,6 +87,12 @@ static inline-class-member method E3|constructor#named(core::int foo, [has-decla
7487
}
7588
static inline-class-member method E3|constructor#_#named#tearOff(core::int foo, [has-declared-initializer invalid-type bar]) → self::E3 /* = core::int */
7689
return self::E3|constructor#named(foo, bar);
90+
static inline-class-member method E4|constructor#(dynamic foo) → self::E4 /* = dynamic */ {
91+
lowered final self::E4 /* = dynamic */ #this = foo;
92+
return #this;
93+
}
94+
static inline-class-member method E4|constructor#_#new#tearOff(dynamic foo) → self::E4 /* = dynamic */
95+
return self::E4|constructor#(foo);
7796

7897
constants {
7998
#C1 = null

0 commit comments

Comments
 (0)