-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Description
Hi, when using the following code snippet, I encountered a bug where the Dart static analyzer does not report an error when not all required parameters are provided to a class constructor.
Additionally, the static analysis seems to freeze when evaluating the code.
However, the error is shown when attempting to compile or run the application in the terminal.
On rare occasions, the static analyzer behaves as expected, showing the corresponding errors.
Case 1:
sealed class BaseClass<A, B, C> {
const BaseClass({
required this.a,
required this.b,
required this.c,
});
final A a;
final B b;
final C c;
}
class AClass<A, B, C> extends BaseClass<A, B, C> {
const AClass({
required super.a,
required super.b,
required super.c,
});
}
void foo<A, B, C, T extends BaseClass<A, B, C>>(List<T Function()> list) {
// ...
}
void main() {
foo<int, int, int, AClass<int, int, int>>([
() => const AClass(a: 1, b: 2, c: 3),
() => const AClass(a: 3), // wrong
]);
}Case 2:
sealed class BaseClass<A, B, C> {
const BaseClass({
required this.a,
required this.b,
required this.c,
});
final A a;
final B b;
final C c;
}
class AClass<A, B, C> extends BaseClass<A, B, C> {
const AClass({
required super.a,
required super.b,
required super.c,
});
}
void foo<A, B, C, T extends BaseClass<A, B, C>>(List<T Function()> list) {
// ...
}
void main() {
foo<int, int, int, AClass<int, int, int>>([f1]);
}
AClass<int, int, int> f1() => const AClass(a: 1);Tested On:
-
Windows with Flutter 3.27.1 with Dart 3.6
-
IDX Platform with the following configuration:
[✓] Flutter (Channel stable, 3.24.3, on IDX GNU/Linux 6.1.112+, locale en_US.UTF-8)
• Flutter version 3.24.3 on channel stable at /home/user/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 2663184aa7 (3 months ago), 2024-09-11 16:27:48 -0500
• Engine revision 36335019a8
• Dart version 3.5.3
• DevTools version 2.37.3- In the DartPad it works normally.
From what I've noticed, the issue seems to arise when using functions that take generics as parameters in combination with sealed classes. I don't know if it occurs in other cases.
This
foo<int, int, int, AClass<int, int, int>>([
// () => const AClass(a: 1, b: 2, c: 3),
// () => const AClass(a: 3),
]);I would appreciate it if you could tell me what the reason is so I can update my code while it is being fixed.
Thanks
