Skip to content

Commit 06d4cd3

Browse files
bwilkersoncommit-bot@chromium.org
authored andcommitted
Add tests to show that combinators work correctly with extensions
Change-Id: Ibe72662d70ff776153814aec960a8409117f0196 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/112266 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Reviewed-by: Phil Quitslund <pquitslund@google.com> Commit-Queue: Brian Wilkerson <brianwilkerson@google.com>
1 parent d19a590 commit 06d4cd3

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

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

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:analyzer/dart/analysis/features.dart';
66
import 'package:analyzer/src/dart/analysis/driver.dart';
7+
import 'package:analyzer/src/error/codes.dart';
78
import 'package:analyzer/src/generated/engine.dart';
89
import 'package:test/test.dart';
910
import 'package:test_reflective_loader/test_reflective_loader.dart';
@@ -152,6 +153,42 @@ extension on C {}
152153
assertElement(extendedType, findElement.class_('C'));
153154
assertType(extendedType, 'C');
154155
}
156+
157+
test_visibility_hidden() async {
158+
newFile('/test/lib/lib.dart', content: '''
159+
class C {}
160+
extension E on C {
161+
int a = 1;
162+
}
163+
''');
164+
await assertErrorsInCode('''
165+
import 'lib.dart' hide E;
166+
167+
f(C c) {
168+
c.a;
169+
}
170+
''', [
171+
error(StaticTypeWarningCode.UNDEFINED_GETTER, 40, 1),
172+
]);
173+
}
174+
175+
test_visibility_notShown() async {
176+
newFile('/test/lib/lib.dart', content: '''
177+
class C {}
178+
extension E on C {
179+
int a = 1;
180+
}
181+
''');
182+
await assertErrorsInCode('''
183+
import 'lib.dart' show C;
184+
185+
f(C c) {
186+
c.a;
187+
}
188+
''', [
189+
error(StaticTypeWarningCode.UNDEFINED_GETTER, 40, 1),
190+
]);
191+
}
155192
}
156193

157194
/// Tests that extension members can be correctly resolved when referenced

0 commit comments

Comments
 (0)