Skip to content

Commit e307c0b

Browse files
chloestefantsovaCommit Bot
authored and
Commit Bot
committed
[cfe] Allow extension members with names as Object static members
Closes #48834 Change-Id: If756cf5b3416b2ed9953fe577b8b2e9490a70dd1 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241603 Reviewed-by: Johnni Winther <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]>
1 parent 4258a05 commit e307c0b

8 files changed

+138
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,8 @@ class SourceExtensionBuilder extends ExtensionBuilderImpl {
106106
Builder? objectGetter = objectClassBuilder.lookupLocalMember(name);
107107
Builder? objectSetter =
108108
objectClassBuilder.lookupLocalMember(name, setter: true);
109-
if (objectGetter != null || objectSetter != null) {
109+
if (objectGetter != null && !objectGetter.isStatic ||
110+
objectSetter != null && !objectSetter.isStatic) {
110111
addProblem(
111112
templateExtensionMemberConflictsWithObjectMember
112113
.withArguments(name),
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Copyright (c) 2022, 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+
extension HashAll on Iterable {
6+
int hashAll() => 0;
7+
}
8+
9+
extension HashAllList on List {
10+
int hashAll() => 1;
11+
}
12+
13+
void main() {
14+
List l = [];
15+
Iterable i = [];
16+
print(l.hashAll());
17+
print(i.hashAll());
18+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extension HashAll on Iterable {
2+
int hashAll() => 0;
3+
}
4+
5+
extension HashAllList on List {
6+
int hashAll() => 1;
7+
}
8+
9+
void main() {}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
extension HashAll on Iterable {
2+
int hashAll() => 0;
3+
}
4+
5+
extension HashAllList on List {
6+
int hashAll() => 1;
7+
}
8+
9+
void main() {}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
extension HashAll on core::Iterable<dynamic> {
6+
method hashAll = self::HashAll|hashAll;
7+
tearoff hashAll = self::HashAll|get#hashAll;
8+
}
9+
extension HashAllList on core::List<dynamic> {
10+
method hashAll = self::HashAllList|hashAll;
11+
tearoff hashAll = self::HashAllList|get#hashAll;
12+
}
13+
static method HashAll|hashAll(lowered final core::Iterable<dynamic> #this) → core::int
14+
return 0;
15+
static method HashAll|get#hashAll(lowered final core::Iterable<dynamic> #this) → () → core::int
16+
return () → core::int => self::HashAll|hashAll(#this);
17+
static method HashAllList|hashAll(lowered final core::List<dynamic> #this) → core::int
18+
return 1;
19+
static method HashAllList|get#hashAll(lowered final core::List<dynamic> #this) → () → core::int
20+
return () → core::int => self::HashAllList|hashAll(#this);
21+
static method main() → void {
22+
core::List<dynamic> l = <dynamic>[];
23+
core::Iterable<dynamic> i = <dynamic>[];
24+
core::print(self::HashAllList|hashAll(l));
25+
core::print(self::HashAll|hashAll(i));
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
extension HashAll on core::Iterable<dynamic> {
6+
method hashAll = self::HashAll|hashAll;
7+
tearoff hashAll = self::HashAll|get#hashAll;
8+
}
9+
extension HashAllList on core::List<dynamic> {
10+
method hashAll = self::HashAllList|hashAll;
11+
tearoff hashAll = self::HashAllList|get#hashAll;
12+
}
13+
static method HashAll|hashAll(lowered final core::Iterable<dynamic> #this) → core::int
14+
return 0;
15+
static method HashAll|get#hashAll(lowered final core::Iterable<dynamic> #this) → () → core::int
16+
return () → core::int => self::HashAll|hashAll(#this);
17+
static method HashAllList|hashAll(lowered final core::List<dynamic> #this) → core::int
18+
return 1;
19+
static method HashAllList|get#hashAll(lowered final core::List<dynamic> #this) → () → core::int
20+
return () → core::int => self::HashAllList|hashAll(#this);
21+
static method main() → void {
22+
core::List<dynamic> l = <dynamic>[];
23+
core::Iterable<dynamic> i = <dynamic>[];
24+
core::print(self::HashAllList|hashAll(l));
25+
core::print(self::HashAll|hashAll(i));
26+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
extension HashAll on core::Iterable<dynamic> {
6+
method hashAll = self::HashAll|hashAll;
7+
tearoff hashAll = self::HashAll|get#hashAll;
8+
}
9+
extension HashAllList on core::List<dynamic> {
10+
method hashAll = self::HashAllList|hashAll;
11+
tearoff hashAll = self::HashAllList|get#hashAll;
12+
}
13+
static method HashAll|hashAll(lowered final core::Iterable<dynamic> #this) → core::int
14+
;
15+
static method HashAll|get#hashAll(lowered final core::Iterable<dynamic> #this) → () → core::int
16+
return () → core::int => self::HashAll|hashAll(#this);
17+
static method HashAllList|hashAll(lowered final core::List<dynamic> #this) → core::int
18+
;
19+
static method HashAllList|get#hashAll(lowered final core::List<dynamic> #this) → () → core::int
20+
return () → core::int => self::HashAllList|hashAll(#this);
21+
static method main() → void
22+
;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
library /*isNonNullableByDefault*/;
2+
import self as self;
3+
import "dart:core" as core;
4+
5+
extension HashAll on core::Iterable<dynamic> {
6+
method hashAll = self::HashAll|hashAll;
7+
tearoff hashAll = self::HashAll|get#hashAll;
8+
}
9+
extension HashAllList on core::List<dynamic> {
10+
method hashAll = self::HashAllList|hashAll;
11+
tearoff hashAll = self::HashAllList|get#hashAll;
12+
}
13+
static method HashAll|hashAll(lowered final core::Iterable<dynamic> #this) → core::int
14+
return 0;
15+
static method HashAll|get#hashAll(lowered final core::Iterable<dynamic> #this) → () → core::int
16+
return () → core::int => self::HashAll|hashAll(#this);
17+
static method HashAllList|hashAll(lowered final core::List<dynamic> #this) → core::int
18+
return 1;
19+
static method HashAllList|get#hashAll(lowered final core::List<dynamic> #this) → () → core::int
20+
return () → core::int => self::HashAllList|hashAll(#this);
21+
static method main() → void {
22+
core::List<dynamic> l = core::_GrowableList::•<dynamic>(0);
23+
core::Iterable<dynamic> i = core::_GrowableList::•<dynamic>(0);
24+
core::print(self::HashAllList|hashAll(l));
25+
core::print(self::HashAll|hashAll(i));
26+
}

0 commit comments

Comments
 (0)