@@ -211,27 +211,6 @@ class ExtensionMemberResolver {
211211 /// identified.
212212 _InstantiatedExtension _chooseMostSpecific (
213213 List <_InstantiatedExtension > extensions) {
214- //
215- // https://github.com/dart-lang/language/blob/master/accepted/future-releases/static-extension-methods/feature-specification.md#extension-conflict-resolution:
216- //
217- // If more than one extension applies to a specific member invocation, then
218- // we resort to a heuristic to choose one of the extensions to apply. If
219- // exactly one of them is "more specific" than all the others, that one is
220- // chosen. Otherwise it is a compile-time error.
221- //
222- // An extension with on type clause T1 is more specific than another
223- // extension with on type clause T2 iff
224- //
225- // 1. T2 is declared in a platform library, and T1 is not, or
226- // 2. they are both declared in platform libraries or both declared in
227- // non-platform libraries, and
228- // 3. the instantiated type (the type after applying type inference from the
229- // receiver) of T1 is a subtype of the instantiated type of T2 and either
230- // not vice versa, or
231- // 4. the instantiate-to-bounds type of T1 is a subtype of the
232- // instantiate-to-bounds type of T2 and not vice versa.
233- //
234-
235214 for (var i = 0 ; i < extensions.length; i++ ) {
236215 var e1 = extensions[i];
237216 var isMoreSpecific = true ;
@@ -418,7 +397,9 @@ class ExtensionMemberResolver {
418397 /// Return `true` is [e1] is more specific than [e2] .
419398 bool _isMoreSpecific (_InstantiatedExtension e1, _InstantiatedExtension e2) {
420399 // 1. The latter extension is declared in a platform library, and the
421- // former extension is not.
400+ // former extension is not.
401+ // 2. They are both declared in platform libraries, or both declared in
402+ // non-platform libraries.
422403 var e1_isInSdk = e1.element.library.isInSdk;
423404 var e2_isInSdk = e2.element.library.isInSdk;
424405 if (e1_isInSdk && ! e2_isInSdk) {
@@ -430,30 +411,25 @@ class ExtensionMemberResolver {
430411 var extendedType1 = e1._extendedType;
431412 var extendedType2 = e2._extendedType;
432413
433- // 2. they are both declared in platform libraries or both declared in
434- // non-platform libraries, and
435- if (_isSubtypeAndNotViceVersa (extendedType1, extendedType2)) {
436- // 3. the instantiated type (the type after applying type inference from
437- // the receiver) of T1 is a subtype of the instantiated type of T2 and
438- // either not vice versa
414+ // 3. The instantiated type (the type after applying type inference from
415+ // the receiver) of T1 is a subtype of the instantiated type of T2,
416+ // and either...
417+ if (! _isSubtypeOf (extendedType1, extendedType2)) {
418+ return false ;
419+ }
420+
421+ // 4. ...not vice versa, or...
422+ if (! _isSubtypeOf (extendedType2, extendedType1)) {
439423 return true ;
440424 }
441425
426+ // 5. ...the instantiate-to-bounds type of T1 is a subtype of the
427+ // instantiate-to-bounds type of T2 and not vice versa.
442428 // TODO(scheglov) store instantiated types
443429 var extendedTypeBound1 = _instantiateToBounds (e1.element);
444430 var extendedTypeBound2 = _instantiateToBounds (e2.element);
445- if (_isSubtypeAndNotViceVersa (extendedTypeBound1, extendedTypeBound2)) {
446- // or:
447- // 4. the instantiate-to-bounds type of T1 is a subtype of the
448- // instantiate-to-bounds type of T2 and not vice versa.
449- return true ;
450- }
451-
452- return false ;
453- }
454-
455- bool _isSubtypeAndNotViceVersa (DartType t1, DartType t2) {
456- return _isSubtypeOf (t1, t2) && ! _isSubtypeOf (t2, t1);
431+ return _isSubtypeOf (extendedTypeBound1, extendedTypeBound2) &&
432+ ! _isSubtypeOf (extendedTypeBound2, extendedTypeBound1);
457433 }
458434
459435 /// Ask the type system for a subtype check.
0 commit comments