Skip to content

Commit 38ca381

Browse files
scheglovcommit-bot@chromium.org
authored andcommitted
Don't include extended type into syntactic scope of extensions.
R=brianwilkerson@google.com Change-Id: I794dbdcef97652d7a7f17421f733f21d2f157de4 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112493 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
1 parent 157336f commit 38ca381

File tree

2 files changed

+112
-7
lines changed

2 files changed

+112
-7
lines changed

pkg/analyzer/lib/src/generated/resolver.dart

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5382,13 +5382,6 @@ abstract class ScopedVisitor extends UnifyingAstVisitor<void> {
53825382
enclosingExtension = extensionElement;
53835383
nameScope = new TypeParameterScope(nameScope, extensionElement);
53845384
visitExtensionDeclarationInScope(node);
5385-
DartType extendedType = extensionElement.extendedType;
5386-
if (extendedType is InterfaceType) {
5387-
nameScope = new ClassScope(nameScope, extendedType.element);
5388-
} else if (extendedType is FunctionType) {
5389-
nameScope =
5390-
new ClassScope(nameScope, typeProvider.functionType.element);
5391-
}
53925385
nameScope = ExtensionScope(nameScope, extensionElement);
53935386
visitExtensionMembersInScope(node);
53945387
} finally {

pkg/analyzer/test/src/dart/resolution/extension_method_test.dart

Lines changed: 112 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,4 +1490,116 @@ extension E on C {
14901490
assertElement(identifier, findElement.method('a'));
14911491
assertType(identifier, 'void Function(int)');
14921492
}
1493+
1494+
test_topLevel_function_fromInstance() async {
1495+
await assertNoErrorsInCode('''
1496+
class C {
1497+
void a() {}
1498+
}
1499+
1500+
void a() {}
1501+
1502+
extension E on C {
1503+
void b() {
1504+
a();
1505+
}
1506+
}
1507+
''');
1508+
var invocation = findNode.methodInvocation('a();');
1509+
assertElement(invocation, findElement.topFunction('a'));
1510+
assertInvokeType(invocation, 'void Function()');
1511+
}
1512+
1513+
test_topLevel_function_fromStatic() async {
1514+
await assertNoErrorsInCode('''
1515+
class C {
1516+
void a() {}
1517+
}
1518+
1519+
void a() {}
1520+
1521+
extension E on C {
1522+
static void b() {
1523+
a();
1524+
}
1525+
}
1526+
''');
1527+
var invocation = findNode.methodInvocation('a();');
1528+
assertElement(invocation, findElement.topFunction('a'));
1529+
assertInvokeType(invocation, 'void Function()');
1530+
}
1531+
1532+
test_topLevel_getter_fromInstance() async {
1533+
await assertNoErrorsInCode('''
1534+
class C {
1535+
int get a => 0;
1536+
}
1537+
1538+
int get a => 0;
1539+
1540+
extension E on C {
1541+
void b() {
1542+
a;
1543+
}
1544+
}
1545+
''');
1546+
var identifier = findNode.simple('a;');
1547+
assertElement(identifier, findElement.topGet('a'));
1548+
assertType(identifier, 'int');
1549+
}
1550+
1551+
test_topLevel_getter_fromStatic() async {
1552+
await assertNoErrorsInCode('''
1553+
class C {
1554+
int get a => 0;
1555+
}
1556+
1557+
int get a => 0;
1558+
1559+
extension E on C {
1560+
static void b() {
1561+
a;
1562+
}
1563+
}
1564+
''');
1565+
var identifier = findNode.simple('a;');
1566+
assertElement(identifier, findElement.topGet('a'));
1567+
assertType(identifier, 'int');
1568+
}
1569+
1570+
test_topLevel_setter_fromInstance() async {
1571+
await assertNoErrorsInCode('''
1572+
class C {
1573+
set a(int _) {}
1574+
}
1575+
1576+
set a(int _) {}
1577+
1578+
extension E on C {
1579+
void b() {
1580+
a = 0;
1581+
}
1582+
}
1583+
''');
1584+
var identifier = findNode.simple('a = 0;');
1585+
assertElement(identifier, findElement.topSet('a'));
1586+
}
1587+
1588+
test_topLevel_setter_fromStatic() async {
1589+
await assertNoErrorsInCode('''
1590+
class C {
1591+
set a(int _) {}
1592+
}
1593+
1594+
set a(int _) {}
1595+
1596+
extension E on C {
1597+
static void b() {
1598+
a = 0;
1599+
}
1600+
}
1601+
''');
1602+
var identifier = findNode.simple('a = 0;');
1603+
assertElement(identifier, findElement.topSet('a'));
1604+
}
14931605
}

0 commit comments

Comments
 (0)