File tree Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -2441,8 +2441,10 @@ abstract class ElementImpl implements Element, Element2 {
24412441 @override
24422442 Element2 ? get enclosingElement2 {
24432443 var candidate = _enclosingElement3;
2444- if (candidate is CompilationUnitElementImpl ||
2445- candidate is AugmentableElement ) {
2444+ if (candidate is CompilationUnitElementImpl ) {
2445+ throw UnsupportedError ('Cannot get an enclosingElement2 for a fragment' );
2446+ }
2447+ if (candidate is AugmentableElement ) {
24462448 throw UnsupportedError ('Cannot get an enclosingElement2 for a fragment' );
24472449 }
24482450 return candidate as Element2 ? ;
@@ -7138,12 +7140,20 @@ mixin MaybeAugmentedInstanceElementMixin
71387140 @override
71397141 E ? thisOrAncestorMatching2 <E extends Element2 >(
71407142 bool Function (Element2 ) predicate,
7141- ) =>
7142- declaration.thisOrAncestorMatching2 (predicate);
7143+ ) {
7144+ if (predicate (this )) {
7145+ return this as E ;
7146+ }
7147+ return library2.thisOrAncestorMatching2 (predicate);
7148+ }
71437149
71447150 @override
7145- E ? thisOrAncestorOfType2 <E extends Element2 >() =>
7146- declaration.thisOrAncestorOfType2 <E >();
7151+ E ? thisOrAncestorOfType2 <E extends Element2 >() {
7152+ if (this case E result) {
7153+ return result;
7154+ }
7155+ return library2.thisOrAncestorOfType2 <E >();
7156+ }
71477157
71487158 @override
71497159 void visitChildren2 <T >(ElementVisitor2 <T > visitor) {
Original file line number Diff line number Diff line change @@ -950,6 +950,11 @@ class _Element2Writer extends _AbstractElementWriter {
950950 }
951951
952952 void _writeInstanceElement (InstanceElement2 e) {
953+ expect (e.thisOrAncestorOfType2 <InstanceElement2 >(), same (e));
954+ expect (e.thisOrAncestorOfType2 <GetterElement >(), isNull);
955+ expect (e.thisOrAncestorMatching2 ((_) => true ), same (e));
956+ expect (e.thisOrAncestorMatching2 ((_) => false ), isNull);
957+
953958 _sink.writeIndentedLine (() {
954959 switch (e) {
955960 case ClassElement2 ():
You can’t perform that action at this time.
0 commit comments