-
-
Notifications
You must be signed in to change notification settings - Fork 7k
[dart] fix some compilation issues and added casts for analyzer implicit-casts flag #8244
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
Conversation
👍 Thanks for opening this issue! The team will review the labels and make any necessary changes. |
modules/openapi-generator/src/main/resources/dart2/class.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/dart2/class.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/dart2/api.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/dart2/class.mustache
Outdated
Show resolved
Hide resolved
You should add a matching |
@kuhnroyal @Grohden |
@agilob would totally use effective dart, I can make the needed changes if @kuhnroyal also agrees edit: effective could be done in another PR to not bloat this one |
I would love to see a linter in dart/dart-io at some point. I usually use lint. |
Pedantic always makes my eyes bleed, it makes Dart have more strict syntax than Java. I personally stick with effective_dart, but I've never used |
I disagree here, since you're adding lint fixes it makes sense to add the linter too! |
Somehow this PR ended up as lint fixes, but my primary problem was the |
Yes, we should have a separate PR for the strong-mode/implicit changes. Can you use the same options I used here #8231 |
No probs, so just add the analysis.yaml so we know what the changes are related to. |
@kuhnroyal my analysis options for the petstore is just: analyzer:
strong-mode:
implicit-casts: false |
Ok so I see the problem now. I never disable implicit casts because that doesn't do much good. On the other hand having |
modules/openapi-generator/src/main/resources/dart2/class.mustache
Outdated
Show resolved
Hide resolved
@kuhnroyal @agilob
I've only learned from your comments about the Edit: I vote for the |
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.
Can you add the analysis yaml file pls?
The one that triggers warnings you fixed here |
8208aec
to
a4f8a21
Compare
@agilob file added |
@kuhnroyal I was bugged about why I had analyzer errors reported on the So just so you know, this code exemplifies a case where this flag can be helpful: void main() {
foo({"a", "b"});
}
void foo(Iterable<String> authNames) {
// implicit-casts: false -> The argument type 'Iterable<String>' can't be assigned to the parameter type 'List<String>'.
// implicit-casts: true -> ok, just runtime error :D
bar(authNames);
}
void bar(List<String> authNames) {
authNames.add("bar");
} |
Yea, that's a good fix. I'll address the bigger issue some time later, it shouldn't be List there :( |
I agree that this is one of the few cases were |
modules/openapi-generator/src/main/resources/dart2/api_client.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/dart2/enum.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache
Outdated
Show resolved
Hide resolved
modules/openapi-generator/src/main/resources/dart2/class.mustache
Outdated
Show resolved
Hide resolved
@kuhnroyal I am the "if the compiler say its ok, then its ok" guy, so after seeing the flag capturing an actual bug I'm not against it - I'm gonna keep using it in personal projects. But I agree that having to cast every single dynamic is annoying and unnecessary, and the dart API that we have is not huge and is not expected to change very often.. so I would keep the flag (explicitly) disabled |
Let's keep what we have here and address linter in another PR. I think it's fair to add the strictest linter in the generated code. I can do it after this gets in.
It compiles = it goes to production! |
In case of autogenerated code I think correctness and type-safety is more important than "I dont like it has 2 casts every 5 lines in files I never modify manually". I use effective-dart in my projects, because it doesnt put many restriction on code I write, but any autogenerated code must be absolutely safe to a high standard (openapi spec) so the strictest linter the better. |
I agree, since it is generated we can add the casts. But they need to be the correct ones and that is not always easy to see. |
@Grohden can you please resolve the merge conflicts when you've time? Thank you. |
# Conflicts: # modules/openapi-generator/src/main/resources/dart2/enum.mustache # modules/openapi-generator/src/main/resources/dart2/enum_inline.mustache
@wing328 I've merged the latest master today and regenerated the needed files.. I probably need to test if the new added anaysis_options.yaml file will affect the new (?) json serializable option... but that's gonna take time if it depends on me |
I can look into it after this one is merged |
@Grohden sorry do you mind resolving the merge conflicts again? We'll put other Dart PRs on hold for the time being. |
# Conflicts: # modules/openapi-generator/src/main/resources/dart2/api_client.mustache # modules/openapi-generator/src/main/resources/dart2/serialization/native/native_enum.mustache # modules/openapi-generator/src/main/resources/dart2/serialization/native/native_enum_inline.mustache # samples/client/petstore/dart2/petstore_client_lib/.openapi-generator/FILES # samples/client/petstore/dart2/petstore_client_lib/lib/api_client.dart # samples/client/petstore/dart2/petstore_client_lib/lib/model/api_response.dart # samples/client/petstore/dart2/petstore_client_lib/lib/model/category.dart # samples/client/petstore/dart2/petstore_client_lib/lib/model/order.dart # samples/client/petstore/dart2/petstore_client_lib/lib/model/pet.dart # samples/client/petstore/dart2/petstore_client_lib/lib/model/tag.dart # samples/client/petstore/dart2/petstore_client_lib/lib/model/user.dart # samples/openapi3/client/petstore/dart-dio-next/petstore_client_lib_fake/analysis_options.yaml # samples/openapi3/client/petstore/dart2/petstore_client_lib/lib/api_client.dart # samples/openapi3/client/petstore/dart2/petstore_client_lib_fake/lib/api_client.dart # samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/model/enum_arrays.dart # samples/openapi3/client/petstore/dart2/petstore_json_serializable_client_lib_fake/lib/model/enum_test.dart
@wing328 no problem I've merged today's master and re-generated all dart codes ( |
Travis CI failure not related to this PR. |
Details
I've made some fixes for the dart templates, @kuhnroyal and I had some discussion on #8179.
My changes were necessary to be able to compile my personal project and also the fake petstore generated clients.
Not all changes were made to fix compile errors: I've mistakenly enabled the
implicit-casts:false
on the generated client and then fixed the resulting analyzer errors..From the changelist listed in #8179 I've fixed:
(I've only fixed the compilation error, not sure if it will work properly on runtime)
Maybe I've fixed other issues.. but I'm not sure, would be glad if someone test it and confirm exactly what is still broken
PR checklist
./bin/generate-samples.sh
to update all Petstore samples related to your fix. This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master. These must match the expectations made by your contribution. You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example./bin/generate-samples.sh bin/configs/java*
. For Windows users, please run the script in Git BASH.master
@kuhnroyal could you comment on the casts you said that were uneeded?
@swipesight @jaumard @josh-burton @amondnet @sbu-WBT @kuhnroyal @agilob