|
| 1 | +When Dart was first designed, the intent was that Dart applications would be |
| 2 | +deployed and run from unprocessed source code on end user machines. That meant |
| 3 | +that a heavyweight compilation process involving complex type checking and type |
| 4 | +inference could slow application startup. Thus the type system was optional, and |
| 5 | +type errors were warnings. |
| 6 | + |
| 7 | +The move to a mandatory static type system in Dart 2.0 turned most of the |
| 8 | +warnings related to the type system into full compile errors. But there were a |
| 9 | +few specified diagnostics that remained warnings. Further, many language |
| 10 | +proposals define additional warnings (for example, unreachable cases in switch |
| 11 | +statements in Dart 3.0). |
| 12 | + |
| 13 | +It has been a source of confusion on the team as to whether every Dart tool is |
| 14 | +required to report all of those warnings, and whether tools are prohibited from |
| 15 | +reporting any warnings not defined by the language. |
| 16 | + |
| 17 | +This document, along with [a corresponding update to the language spec][spec |
| 18 | +change] clarifies that. |
| 19 | + |
| 20 | +[spec change]: https://github.com/dart-lang/language/pull/3570 |
| 21 | + |
| 22 | +## Specifying warnings |
| 23 | + |
| 24 | +After Dart 2.0 change most static warnings to type errors, there were few |
| 25 | +warnings left in the spec. Because of that, we have sometimes considered |
| 26 | +removing all warnings from the spec and leaving it entirely up to implementation |
| 27 | +teams to define them and decide what to report and when. |
| 28 | + |
| 29 | +However, when writing feature specifications for new language features, we often |
| 30 | +find ourselves wanting to suggest new warnings. This is *not* because we want to |
| 31 | +force every Dart implementation to report every one of these warnings. It's |
| 32 | +because it's important to think holistically about the entire user experience |
| 33 | +when defining a new language feature. The tooling experience—warnings, lints, |
| 34 | +migration tools, quick fixes etc.—around a feature can make the difference |
| 35 | +between a good feature and a bad feature. |
| 36 | + |
| 37 | +Putting warnings (and lints, quick fixes, etc.) in feature proposals helps |
| 38 | +ensure the language team does that due diligence. At the same time, we don't |
| 39 | +want to discard the expertise of the implementation teams about what makes the |
| 40 | +best user experience and diagnostics for their tool. We're just trying to do |
| 41 | +good, thorough design. |
| 42 | + |
| 43 | +## Reporting warnings |
| 44 | + |
| 45 | +Given a set of specified warnings, what obligations do Dart implementations have |
| 46 | +to implement them? In principle, it would be good if all of our tools behaved |
| 47 | +the same and they all reported all warnings. That way users get a consistent |
| 48 | +experience. |
| 49 | + |
| 50 | +But the reality is that we have two very different static analysis |
| 51 | +implementations: analyzer and common front end (CFE). Requiring both of them to |
| 52 | +report all of the same warnings would be a large and continuous engineering |
| 53 | +effort for relatively little benefit. Most warnings are seen by users and |
| 54 | +addressed by them in their IDE. As long as analyzer reports them, most of the |
| 55 | +user benefit is provided. The CFE isn't usually invoked until the user wants to |
| 56 | +generate code for a runnable program. If they choose to do that, they are |
| 57 | +implicitly ignoring warnings anyway, so having the CFE report them adds only |
| 58 | +marginal value. |
| 59 | + |
| 60 | +Also, some warnings are specific to certain tools. For example, a web compiler |
| 61 | +might report warnings on `is int` and `is double` since those may not behave as |
| 62 | +expected in JavaScript where the same representation is used for all numbers. It |
| 63 | +would be strange and confusing if a compiler *not* targeting the web reported that |
| 64 | +warning when it wouldn't be relevant on the platform the user is compiling for. |
| 65 | + |
| 66 | +Consider that the reason these diagnostics being warnings and not errors is |
| 67 | +specifically to allow variation in how they how they are reported to and handled |
| 68 | +by users. If there's a diagnostic that we really feel should always be presented |
| 69 | +to all users and they should definitely handle it... it should probably be an |
| 70 | +error. |
| 71 | + |
| 72 | +## Warning reporting requirements |
| 73 | + |
| 74 | +Given all of the above, the position of the language team on warnings is: |
| 75 | + |
| 76 | +* The language specification and feature specifications for new features may |
| 77 | + suggest new warnings that the language team believes will help the user |
| 78 | + experience. |
| 79 | + |
| 80 | +* A conforming Dart implementation is free to report any, all, some, or none |
| 81 | + of those specified warnings. |
| 82 | + |
| 83 | +* Further, a Dart implementation may choose to report its own warnings that |
| 84 | + aren't part of the language spec or any feature proposal. |
| 85 | + |
| 86 | +*In other words, both the language team and implementation teams may add to the |
| 87 | +set of all possible warnings, and the implementation teams can decide which of |
| 88 | +those warnings make sense for their tools to report.* |
| 89 | + |
| 90 | +*In practice, we expect the analyzer to report them all (and let us know if we |
| 91 | +specify any that they believe aren't helpful). Going forward, it's likely the |
| 92 | +CFE will stop reporting any of them.* |
0 commit comments