Skip to content

Commit c1b7d34

Browse files
jensjohaCommit Queue
authored andcommitted
[CFE] Fix crash with ExtensionType and duplicates causing parents not to be set
Change-Id: I107009e585e13082722ff33035a898185b93208a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394980 Commit-Queue: Jens Johansen <[email protected]> Reviewed-by: Johnni Winther <[email protected]>
1 parent 34a6cbc commit c1b7d34

8 files changed

+150
-1
lines changed

pkg/front_end/lib/src/kernel/hierarchy/extension_type_members.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,9 @@ class ExtensionTypeMembersNodeBuilder extends MembersNodeBuilder {
186186
extensionTypeMemberMap: extensionTypeSetableMap);
187187
}
188188
if (extensionTypeDeclarationBuilder
189-
is SourceExtensionTypeDeclarationBuilder) {
189+
is SourceExtensionTypeDeclarationBuilder &&
190+
// The check needs parents which aren't set on duplicates.
191+
!extensionTypeDeclarationBuilder.isDuplicate) {
190192
if (getableMember != null &&
191193
setableMember != null &&
192194
getableMember.isProperty &&
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// Copyright (c) 2024, 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+
int foo = 42;
6+
7+
extension type foo(String foo) {
8+
set foo(double x) { }
9+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:8:7: Error: A class member can't have the same name as the enclosing class.
6+
// Try renaming the member.
7+
// set foo(double x) { }
8+
// ^^^
9+
//
10+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:16: Error: 'foo' is already declared in this scope.
11+
// extension type foo(String foo) {
12+
// ^^^
13+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:5:5: Context: Previous declaration of 'foo'.
14+
// int foo = 42;
15+
// ^^^
16+
//
17+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:27: Error: A class member can't have the same name as the enclosing class.
18+
// Try renaming the member.
19+
// extension type foo(String foo) {
20+
// ^
21+
//
22+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:8:7: Error: 'foo' isn't a type.
23+
// set foo(double x) { }
24+
// ^
25+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:27: Context: This isn't a type.
26+
// extension type foo(String foo) {
27+
// ^
28+
//
29+
import self as self;
30+
import "dart:core" as core;
31+
32+
static field core::int foo = 42;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:8:7: Error: A class member can't have the same name as the enclosing class.
6+
// Try renaming the member.
7+
// set foo(double x) { }
8+
// ^^^
9+
//
10+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:16: Error: 'foo' is already declared in this scope.
11+
// extension type foo(String foo) {
12+
// ^^^
13+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:5:5: Context: Previous declaration of 'foo'.
14+
// int foo = 42;
15+
// ^^^
16+
//
17+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:27: Error: A class member can't have the same name as the enclosing class.
18+
// Try renaming the member.
19+
// extension type foo(String foo) {
20+
// ^
21+
//
22+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:8:7: Error: 'foo' isn't a type.
23+
// set foo(double x) { }
24+
// ^
25+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:27: Context: This isn't a type.
26+
// extension type foo(String foo) {
27+
// ^
28+
//
29+
import self as self;
30+
import "dart:core" as core;
31+
32+
static field core::int foo = 42;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:8:7: Error: A class member can't have the same name as the enclosing class.
6+
// Try renaming the member.
7+
// set foo(double x) { }
8+
// ^^^
9+
//
10+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:16: Error: 'foo' is already declared in this scope.
11+
// extension type foo(String foo) {
12+
// ^^^
13+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:5:5: Context: Previous declaration of 'foo'.
14+
// int foo = 42;
15+
// ^^^
16+
//
17+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:27: Error: A class member can't have the same name as the enclosing class.
18+
// Try renaming the member.
19+
// extension type foo(String foo) {
20+
// ^
21+
//
22+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:8:7: Error: 'foo' isn't a type.
23+
// set foo(double x) { }
24+
// ^
25+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:27: Context: This isn't a type.
26+
// extension type foo(String foo) {
27+
// ^
28+
//
29+
import self as self;
30+
import "dart:core" as core;
31+
32+
static field core::int foo;
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
library;
2+
//
3+
// Problems in library:
4+
//
5+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:8:7: Error: A class member can't have the same name as the enclosing class.
6+
// Try renaming the member.
7+
// set foo(double x) { }
8+
// ^^^
9+
//
10+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:16: Error: 'foo' is already declared in this scope.
11+
// extension type foo(String foo) {
12+
// ^^^
13+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:5:5: Context: Previous declaration of 'foo'.
14+
// int foo = 42;
15+
// ^^^
16+
//
17+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:27: Error: A class member can't have the same name as the enclosing class.
18+
// Try renaming the member.
19+
// extension type foo(String foo) {
20+
// ^
21+
//
22+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:8:7: Error: 'foo' isn't a type.
23+
// set foo(double x) { }
24+
// ^
25+
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:27: Context: This isn't a type.
26+
// extension type foo(String foo) {
27+
// ^
28+
//
29+
import self as self;
30+
import "dart:core" as core;
31+
32+
static field core::int foo = 42;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int foo = 42;
2+
3+
extension type foo(String foo) {
4+
set foo(double x) {}
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
extension type foo(String foo) {
2+
set foo(double x) {}
3+
}
4+
5+
int foo = 42;

0 commit comments

Comments
 (0)