Closed
Description
When running the demo_220216
with Dart 2.19.2
and setting the minimum SDK version to 2.17.0
, a type inference error occurs. However, with Flutter 3.3/Dart 2.18, there is no problem. Setting the minimum SDK version to 2.18.0+
also does not cause any issues.
Dart Version: Dart SDK version: 2.19.2 (stable) (Tue Feb 7 18:37:17 2023 +0000) on "macos_arm64"
Demo
Code:
demo_220216.zip
bin/demo_220216.dart
:
class Value<T> {
const Value({
required this.getter,
required this.setter,
});
final T Function() getter;
final void Function(T value) setter;
}
final v = Value(
getter: () => 1,
setter: (value) {
int intValue = value;
print(intValue);
},
);
void main() {
print(v);
}
pubspec.yaml
:
environment:
# sdk: '>=2.19.0 <3.0.0' # Success
# sdk: '>=2.18.0 <3.0.0' # Success
sdk: '>=2.17.0 <3.0.0' # Error: A value of type 'Object?' can't be assigned to a variable of type 'int'.
Except Output:
Instance of 'Value<int>'
Actual Output(Compile error):
bin/demo_220216.dart:13:20: Error: A value of type 'Object?' can't be assigned to a variable of type 'int'.
- 'Object' is from 'dart:core'.
int intValue = value;
^
Metadata
Metadata
Assignees
Labels
No labels