- Notifications
You must be signed in to change notification settings - Fork 1.7k
Open
Labels
area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.
Description
I'm not sure whether this is a valid bug, but consider this:
// a.dart class A { void _privateMethod() {} void method() {} } void doSomethingOnA(A a) { a.method(); a._privateMethod(); } // main.dart import 'a.dart'; class B implements A { @override void method() { // Implementation of method } } void main() { final a = A(); doSomethingOnA(a); final b = B(); doSomethingOnA(b); runApp(const MyApp()); }There is no lints or compilation errors, but at run time:
Tried calling: _privateMethod() #0 B._privateMethod (package:my_app/b.dart:3:7) #1 doSomethingOnA (package:my_app/a.dart:9:5) #2 main (package:my_app/main.dart:9:3) #3 _runMain.<anonymous closure> (dart:ui/hooks.dart:319:23) #4 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:314:19) #5 _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:193:12) And this doesn't happen if I define B in a.dart:
// a.dart class A { void _privateMethod() {} void method() {} } class B implements A { // <- lint here: Missing concrete implementation of 'class A._privateMethod'. Try implementing the missing method, or make the class @override void method() { // Implementation of method } } void doSomethingOnA(A a) { a.method(); a._privateMethod(); }Analyzing a.dart... 0.3s error • a.dart:7:7 • Missing concrete implementation of 'class A._privateMethod'. Try implementing the missing method, or make the class abstract. • non_abstract_class_inherits_abstract_member 1 issue found. Is there something we can do to avoid the runtime issue described?
Some ideas:
- Have the lint in
main.dartwhenB implements A - Force a class modifier (
final,sealed) whenAhas private method used in public APIs (doSomethingWithA)
Metadata
Metadata
Assignees
Labels
area-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.