-
Notifications
You must be signed in to change notification settings - Fork 396
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
generated code fails static analysis strong type checking #247
Comments
I support Why are you using |
Why do I use I've decades in strongly-checked languages and have learned that errant code is more easily found when types are declared, known, and checked. The rigidity forces programmers to think about the object/class/hierarchies, to fully declare their interfaces which helps both caller and implementer know the rules/boundaries, and to enable tools (like the analyzer) to verify that code is following the rules which are stated. The user-programmer is responsible for declaring what they want the system to do. The compiler-implementer is responsible for turning that into machine code and optimizing. I rely on and trust the compiler-phase to remove/reduce overhead related to type-checking. And in some cases, to actually run faster/be small because it doesn't need to do run-time type checking so it can remove that chunk of code. I think the use of generics/templates is a nice middle ground allowing strong typing while also allowing flexibility in writing generic-behaving code. That topic set aside, this could also be a conversation on the topic of "When code is generated, does the Dart ecosystem/community want to treat it differently regarding analysis, checks, linting, etc. One might say that generated code coming from core teams should be reference-quality and pass all tests/lints/analyzers. That any coder can look at the generated code to learn language usage, techniques, etc. Another approach on that generated code topic might be that it should not be seen by user-programmers, should be obfuscated, should not be leveraged as user-code techniques, etc. In this perspective, I recommend removing all unneeded whitespace ala minify and somehow prevent type-checking by static/analysis tools so that user-programmers are not distracted by those same tools when they report errant behavior/style in the generated code. |
See the discussion here #73 We are pondering some more strict checks that are less onerous than |
fwiw, i have made a very simple builder which allows to add |
Related to dart-lang/source_gen#370 We need to get this back! |
Can I add my voice to getting a resolution for this.
|
+1 We also face this problem. Strong mode is quite helpful as it reduces bugs! |
We're likely not going to change this. It adds A LOT of extra code. Try this in your # Read about `build.yaml` at https://pub.dev/packages/build_config
# To update generated code, run `pub run build_runner build`
targets:
$default:
builders:
source_gen|combining_builder:
options:
ignore_for_file:
- strong_mode_implicit_dynamic_parameter ...or similar for whichever lint/hint you want to ignore |
@kevmoo I see. Indeed it is renamed to |
The code generated does not have types on several parameters. It also implicitly casts to a more specific type. This is loosely typed and fails static analysis w/ strong checking.
The generated code functions. Rather, these errors appear in IDEs and other tools that digest code analysis. So the fix is to provide a way to understand or rid the errors.
Setup
Repo steps
Item
which has some simple fields like aString
andint
.MyGroup
which has a fieldList<Item> myItems;
andSet<Item> myItemSet;
flutter packages pub run build_runner build
Result
Errors in your IDE for that generated code. You can see in the dart files and the missing param types.
In the below generated code, the
e
has no type declared. Then, the Iterable created from the Json is being assigned to a Set.Possible Quick Fixes
analysis_options.yaml
to ignore the generated files with a glob that matches only the generated files with loose types.or
dynamic
before the two scenarios having thee
parameter..map
, for example?.map<Item>((
new Set<Item>.from(...)
around the whole IterableThe text was updated successfully, but these errors were encountered: