File tree Expand file tree Collapse file tree 3 files changed +43
-0
lines changed
Expand file tree Collapse file tree 3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change @@ -146,6 +146,36 @@ class EnclosedScope extends Scope {
146146 }
147147}
148148
149+ /// The scope defined by an extension.
150+ class ExtensionScope extends EnclosedScope {
151+ /// Initialize a newly created scope, enclosed within the [enclosingScope] ,
152+ /// that represents the given [_extensionElement] .
153+ ExtensionScope (Scope enclosingScope, ExtensionElement extensionElement)
154+ : super (enclosingScope) {
155+ _defineMembers (extensionElement);
156+ }
157+
158+ /// Define the static members defined by the given [extensionElement] . The
159+ /// instance members should only be found if they would be found by normal
160+ /// lookup on `this` .
161+ void _defineMembers (ExtensionElement extensionElement) {
162+ List <PropertyAccessorElement > accessors = extensionElement.accessors;
163+ int accessorLength = accessors.length;
164+ for (int i = 0 ; i < accessorLength; i++ ) {
165+ if (accessors[i].isStatic) {
166+ define (accessors[i]);
167+ }
168+ }
169+ List <MethodElement > methods = extensionElement.methods;
170+ int methodLength = methods.length;
171+ for (int i = 0 ; i < methodLength; i++ ) {
172+ if (methods[i].isStatic) {
173+ define (methods[i]);
174+ }
175+ }
176+ }
177+ }
178+
149179/**
150180 * The scope defined by a function.
151181 */
Original file line number Diff line number Diff line change @@ -5993,6 +5993,7 @@ abstract class ScopedVisitor extends UnifyingAstVisitor<void> {
59935993 // TODO(brianwilkerson) Figure out what, if anything, to do here.
59945994 throw UnsupportedError ('Extension of function type' );
59955995 }
5996+ nameScope = ExtensionScope (nameScope, extensionElement);
59965997 visitExtensionMembersInScope (node);
59975998 }
59985999 } finally {
Original file line number Diff line number Diff line change 7878 expect (invocation.identifier.staticElement, declaration.declaredElement);
7979 }
8080
81+ test_accessStaticWithinInstance () async {
82+ await assertNoErrorsInCode ('''
83+ class A {}
84+ extension E on A {
85+ static void a() {}
86+ void b() { a(); }
87+ }
88+ ''' );
89+ var invocation = findNode.methodInvocation ('a();' );
90+ assertElement (invocation, findElement.method ('a' ));
91+ }
92+
8193 test_method_moreSpecificThanPlatform () async {
8294 //
8395 // An extension with on type clause T1 is more specific than another
You can’t perform that action at this time.
0 commit comments