Closed as not planned
Closed as not planned
Description
I didn't find any related issues, please link to this if any.
Consider the code:
class A {
void test({
String test = 'default',
}) {}
}
class C extends A {
@override
void test({
String test, // <- missing_default_value_for_parameter
}) {}
}
The above code will always report an error in the null-safety world (not sure if it's the same in non-null-safety). To avoid the error, we might turn the code into this to avoid redundant hard-code content:
const _defaultTestString = 'default';
class A {
void test({
String test = _defaultTestString,
}) {}
}
class C extends A {
@override
void test({
String test = _defaultTestString,
}) {}
}
However, in Kotlin, the default value cannot be re-defined if it's overriding a method:
open class A() {
open fun test(test: String = "default") {}
}
class C() : A() {
override fun test(
test: String = "default" // <- Error: An overriding function is not allowed to specify default values for its parameters
) {}
}
I think it can be useful for Dart to handle this, or we can make arguments as super arguments (but super
here seems in a bad semantic condition):
class A {
void test({String test = 'default'}) {}
}
class C extends A {
@override
void test({super.test}) {}
}