Skip to content

Commit

Permalink
[CFE] Fix crash on extension type with duplicate name (2)
Browse files Browse the repository at this point in the history
Change-Id: Id0464bbabbcbc535761acd5b2cc0082ffb8ad6b0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/397800
Commit-Queue: Jens Johansen <[email protected]>
Reviewed-by: Johnni Winther <[email protected]>
  • Loading branch information
jensjoha authored and Commit Queue committed Nov 27, 2024
1 parent e88020b commit 4ce2720
Show file tree
Hide file tree
Showing 15 changed files with 194 additions and 21 deletions.
3 changes: 3 additions & 0 deletions pkg/front_end/lib/src/source/source_builder_mixins.dart
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@ mixin SourceDeclarationBuilderMixin
}
addMemberDescriptorInternal(
memberBuilder, memberKind, memberReference, tearOffReference);
} else {
// Still set parent to avoid crashes.
member.parent = libraryBuilder.library;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

int DuplicateName = 42;

extension type DuplicateName._(int _x){
extension type DuplicateName._(int _x) {
DuplicateName(this._x) {
bar;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:7:16: Error: 'DuplicateName' is already declared in this scope.
// extension type DuplicateName._(int _x){
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:7:16: Error: 'DuplicateName' is already declared in this scope.
// extension type DuplicateName._(int _x) {
// ^^^^^^^^^^^^^
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:5:5: Context: Previous declaration of 'DuplicateName'.
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:5:5: Context: Previous declaration of 'DuplicateName'.
// int DuplicateName = 42;
// ^^^^^^^^^^^^^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:11:11: Error: 'DuplicateName' isn't a type.
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:11:11: Error: 'DuplicateName' isn't a type.
// int get bar => 42;
// ^
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:11:11: Context: This isn't a type.
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:11:11: Context: This isn't a type.
// int get bar => 42;
// ^
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:7:16: Error: 'DuplicateName' is already declared in this scope.
// extension type DuplicateName._(int _x){
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:7:16: Error: 'DuplicateName' is already declared in this scope.
// extension type DuplicateName._(int _x) {
// ^^^^^^^^^^^^^
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:5:5: Context: Previous declaration of 'DuplicateName'.
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:5:5: Context: Previous declaration of 'DuplicateName'.
// int DuplicateName = 42;
// ^^^^^^^^^^^^^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:11:11: Error: 'DuplicateName' isn't a type.
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:11:11: Error: 'DuplicateName' isn't a type.
// int get bar => 42;
// ^
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:11:11: Context: This isn't a type.
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:11:11: Context: This isn't a type.
// int get bar => 42;
// ^
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:7:16: Error: 'DuplicateName' is already declared in this scope.
// extension type DuplicateName._(int _x){
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:7:16: Error: 'DuplicateName' is already declared in this scope.
// extension type DuplicateName._(int _x) {
// ^^^^^^^^^^^^^
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:5:5: Context: Previous declaration of 'DuplicateName'.
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:5:5: Context: Previous declaration of 'DuplicateName'.
// int DuplicateName = 42;
// ^^^^^^^^^^^^^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:11:11: Error: 'DuplicateName' isn't a type.
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:11:11: Error: 'DuplicateName' isn't a type.
// int get bar => 42;
// ^
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:11:11: Context: This isn't a type.
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:11:11: Context: This isn't a type.
// int get bar => 42;
// ^
//
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@ library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:7:16: Error: 'DuplicateName' is already declared in this scope.
// extension type DuplicateName._(int _x){
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:7:16: Error: 'DuplicateName' is already declared in this scope.
// extension type DuplicateName._(int _x) {
// ^^^^^^^^^^^^^
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:5:5: Context: Previous declaration of 'DuplicateName'.
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:5:5: Context: Previous declaration of 'DuplicateName'.
// int DuplicateName = 42;
// ^^^^^^^^^^^^^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:11:11: Error: 'DuplicateName' isn't a type.
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:11:11: Error: 'DuplicateName' isn't a type.
// int get bar => 42;
// ^
// pkg/front_end/testcases/regress/extension_type_duplicate_name.dart:11:11: Context: This isn't a type.
// pkg/front_end/testcases/regress/extension_type_duplicate_name_01.dart:11:11: Context: This isn't a type.
// int get bar => 42;
// ^
//
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
// 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 DuplicateName = 42;

extension type DuplicateName._(int _x) {
static set bar(int newBar) {}
int get bar => 42;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:7:16: Error: 'DuplicateName' is already declared in this scope.
// extension type DuplicateName._(int _x) {
// ^^^^^^^^^^^^^
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:5:5: Context: Previous declaration of 'DuplicateName'.
// int DuplicateName = 42;
// ^^^^^^^^^^^^^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Error: 'DuplicateName' isn't a type.
// int get bar => 42;
// ^
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Context: This isn't a type.
// int get bar => 42;
// ^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:8:14: Error: Conflicts with member 'bar'.
// static set bar(int newBar) {}
// ^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Error: Conflicts with setter 'bar'.
// int get bar => 42;
// ^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:8:14: Error: This static member conflicts with an instance member.
// static set bar(int newBar) {}
// ^^^
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Context: This is the instance member.
// int get bar => 42;
// ^^^
//
import self as self;
import "dart:core" as core;

static field core::int DuplicateName = 42;
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:7:16: Error: 'DuplicateName' is already declared in this scope.
// extension type DuplicateName._(int _x) {
// ^^^^^^^^^^^^^
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:5:5: Context: Previous declaration of 'DuplicateName'.
// int DuplicateName = 42;
// ^^^^^^^^^^^^^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Error: 'DuplicateName' isn't a type.
// int get bar => 42;
// ^
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Context: This isn't a type.
// int get bar => 42;
// ^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:8:14: Error: Conflicts with member 'bar'.
// static set bar(int newBar) {}
// ^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Error: Conflicts with setter 'bar'.
// int get bar => 42;
// ^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:8:14: Error: This static member conflicts with an instance member.
// static set bar(int newBar) {}
// ^^^
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Context: This is the instance member.
// int get bar => 42;
// ^^^
//
import self as self;
import "dart:core" as core;

static field core::int DuplicateName = 42;
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:7:16: Error: 'DuplicateName' is already declared in this scope.
// extension type DuplicateName._(int _x) {
// ^^^^^^^^^^^^^
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:5:5: Context: Previous declaration of 'DuplicateName'.
// int DuplicateName = 42;
// ^^^^^^^^^^^^^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Error: 'DuplicateName' isn't a type.
// int get bar => 42;
// ^
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Context: This isn't a type.
// int get bar => 42;
// ^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:8:14: Error: Conflicts with member 'bar'.
// static set bar(int newBar) {}
// ^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Error: Conflicts with setter 'bar'.
// int get bar => 42;
// ^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:8:14: Error: This static member conflicts with an instance member.
// static set bar(int newBar) {}
// ^^^
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Context: This is the instance member.
// int get bar => 42;
// ^^^
//
import self as self;
import "dart:core" as core;

static field core::int DuplicateName;
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
library;
//
// Problems in library:
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:7:16: Error: 'DuplicateName' is already declared in this scope.
// extension type DuplicateName._(int _x) {
// ^^^^^^^^^^^^^
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:5:5: Context: Previous declaration of 'DuplicateName'.
// int DuplicateName = 42;
// ^^^^^^^^^^^^^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Error: 'DuplicateName' isn't a type.
// int get bar => 42;
// ^
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Context: This isn't a type.
// int get bar => 42;
// ^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:8:14: Error: Conflicts with member 'bar'.
// static set bar(int newBar) {}
// ^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Error: Conflicts with setter 'bar'.
// int get bar => 42;
// ^
//
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:8:14: Error: This static member conflicts with an instance member.
// static set bar(int newBar) {}
// ^^^
// pkg/front_end/testcases/regress/extension_type_duplicate_name_02.dart:9:11: Context: This is the instance member.
// int get bar => 42;
// ^^^
//
import self as self;
import "dart:core" as core;

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

extension type DuplicateName._(int _x) {
static set bar(int newBar) {}
int get bar => 42;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
extension type DuplicateName._(int _x) {
int get bar => 42;
static set bar(int newBar) {}
}

int DuplicateName = 42;

0 comments on commit 4ce2720

Please sign in to comment.