We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
This code does not compile:
import 'dart:convert'; class IntConverter extends Converter<String, int> { @override int convert(String s) => int.parse(s); } class DoubleConverter extends Converter<String, double> { @override double convert(String s) => double.parse(s); } Converter<Object?, Object?>? selectConverter(String name) { // OK Converter<Object?, Object?> c1 = IntConverter(); // OK Converter<Object?, Object?> c2 = DoubleConverter(); // NOT OK: return switch(name) { 'int' => IntConverter(), 'double' => DoubleConverter(), _ => null, }; }
The error says:
A value of type 'Object?' can't be returned from the function 'selectConverter' because it has a return type of 'Converter<Object?, Object?>?'.
However, as c1 and c2 show, the types should check.
c1
c2
Indeed, with a switch statement it works:
Converter<Object?, Object?>? selectConverter(String name) { switch(name) { case 'int': return IntConverter(); case 'double': return DoubleConverter(); default: return null; } }
It's a minor inconvenience, of course, but hopefully can be fixed.
The text was updated successfully, but these errors were encountered:
I believe this is an example of this issue (see my comment as of March 31). There is work in progress to address this. cc @stereotype441
Sorry, something went wrong.
No branches or pull requests
This code does not compile:
The error says:
However, as
c1
andc2
show, the types should check.Indeed, with a switch statement it works:
It's a minor inconvenience, of course, but hopefully can be fixed.
The text was updated successfully, but these errors were encountered: