-
Notifications
You must be signed in to change notification settings - Fork 29.8k
[flutter_tools] Fix type error in ChromiumDevice.startApp #111935
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[flutter_tools] Fix type error in ChromiumDevice.startApp #111935
Conversation
| @override | ||
| Future<LaunchResult> startApp( | ||
| covariant WebApplicationPackage package, { | ||
| WebApplicationPackage? package, { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not directly relevant to the fix, but this type doesn't need to be covariant, as sub-classes will use the exact same type
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this true? Or is it because it has been labeled covariant in the base class definition here:
flutter/packages/flutter_tools/lib/src/device.dart
Lines 591 to 604 in b70ff4f
| /// Start an app package on the current device. | |
| /// | |
| /// [platformArgs] allows callers to pass platform-specific arguments to the | |
| /// start call. The build mode is not used by all platforms. | |
| Future<LaunchResult> startApp( | |
| covariant ApplicationPackage? package, { | |
| String? mainPath, | |
| String? route, | |
| required DebuggingOptions debuggingOptions, | |
| Map<String, Object?> platformArgs, | |
| bool prebuiltApplication = false, | |
| bool ipv6 = false, | |
| String? userIdentifier, | |
| }); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is what true? That the type doesn't need to be covariant? Or that it's not relevant to the fix?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it true that a subtyped class can be passed as a valid parameter to a method.
Meaning I don't think because WebApplicationPackage is a subtype of ApplicationPackage that we can pass it as a valid type to the startApp method. But it works because we marked the type on super class a covariant
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We sync'd offline. To clarify my original statement, I can remove the covariant from the ChromiumDevice.startApp implementation because the super class has it marked covariant. TIL that covariant can be placed in either the superclass or subclass: https://dart.dev/guides/language/sound-problems#the-covariant-keyword
|
LGTM |
Fixes #111877
The issue was that the method declaration in the super class (
Device.startApp) specifiescovariant ApplicationPackage?, while the sub-class (ChromiumDevice.startApp) declares itcovariant WebApplicationPackage, which is non-nullable. However, because of #55531, it is possible to run a Flutter app on a browser device even if the project does not specify a web target; thus, package could legitimately be null. However,ChromiumDevice.startAppspecifies a non-nullable parameter, it is a runtime error. This was likely introduced during a null-safety migration, so this restores this functionality by making the parameter nullable (note thatChromiumDevice.startAppdoes not even reference the argument).