Skip to content

Commit

Permalink
[CFE] Fix crash with ExtensionType and duplicates causing parents not…
Browse files Browse the repository at this point in the history
… 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]>
  • Loading branch information
jensjoha authored and Commit Queue committed Nov 13, 2024
1 parent 34a6cbc commit c1b7d34
Show file tree
Hide file tree
Showing 8 changed files with 150 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,9 @@ class ExtensionTypeMembersNodeBuilder extends MembersNodeBuilder {
extensionTypeMemberMap: extensionTypeSetableMap);
}
if (extensionTypeDeclarationBuilder
is SourceExtensionTypeDeclarationBuilder) {
is SourceExtensionTypeDeclarationBuilder &&
// The check needs parents which aren't set on duplicates.
!extensionTypeDeclarationBuilder.isDuplicate) {
if (getableMember != null &&
setableMember != null &&
getableMember.isProperty &&
Expand Down
9 changes: 9 additions & 0 deletions pkg/front_end/testcases/regress/duplicate_builder_01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// Copyright (c) 2024, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

int foo = 42;

extension type foo(String foo) {
set foo(double x) { }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
library;
//
// Problems in library:
//
// 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.
// Try renaming the member.
// set foo(double x) { }
// ^^^
//
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:16: Error: 'foo' is already declared in this scope.
// extension type foo(String foo) {
// ^^^
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:5:5: Context: Previous declaration of 'foo'.
// int foo = 42;
// ^^^
//
// 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.
// Try renaming the member.
// extension type foo(String foo) {
// ^
//
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:8:7: Error: 'foo' isn't a type.
// set foo(double x) { }
// ^
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:27: Context: This isn't a type.
// extension type foo(String foo) {
// ^
//
import self as self;
import "dart:core" as core;

static field core::int foo = 42;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
library;
//
// Problems in library:
//
// 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.
// Try renaming the member.
// set foo(double x) { }
// ^^^
//
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:16: Error: 'foo' is already declared in this scope.
// extension type foo(String foo) {
// ^^^
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:5:5: Context: Previous declaration of 'foo'.
// int foo = 42;
// ^^^
//
// 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.
// Try renaming the member.
// extension type foo(String foo) {
// ^
//
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:8:7: Error: 'foo' isn't a type.
// set foo(double x) { }
// ^
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:27: Context: This isn't a type.
// extension type foo(String foo) {
// ^
//
import self as self;
import "dart:core" as core;

static field core::int foo = 42;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
library;
//
// Problems in library:
//
// 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.
// Try renaming the member.
// set foo(double x) { }
// ^^^
//
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:16: Error: 'foo' is already declared in this scope.
// extension type foo(String foo) {
// ^^^
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:5:5: Context: Previous declaration of 'foo'.
// int foo = 42;
// ^^^
//
// 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.
// Try renaming the member.
// extension type foo(String foo) {
// ^
//
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:8:7: Error: 'foo' isn't a type.
// set foo(double x) { }
// ^
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:27: Context: This isn't a type.
// extension type foo(String foo) {
// ^
//
import self as self;
import "dart:core" as core;

static field core::int foo;
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
library;
//
// Problems in library:
//
// 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.
// Try renaming the member.
// set foo(double x) { }
// ^^^
//
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:16: Error: 'foo' is already declared in this scope.
// extension type foo(String foo) {
// ^^^
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:5:5: Context: Previous declaration of 'foo'.
// int foo = 42;
// ^^^
//
// 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.
// Try renaming the member.
// extension type foo(String foo) {
// ^
//
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:8:7: Error: 'foo' isn't a type.
// set foo(double x) { }
// ^
// pkg/front_end/testcases/regress/duplicate_builder_01.dart:7:27: Context: This isn't a type.
// extension type foo(String foo) {
// ^
//
import self as self;
import "dart:core" as core;

static field core::int foo = 42;
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
int foo = 42;

extension type foo(String foo) {
set foo(double x) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extension type foo(String foo) {
set foo(double x) {}
}

int foo = 42;

0 comments on commit c1b7d34

Please sign in to comment.