ClojureDart
ClojureDart copied to clipboard
Fail at compile time on dubious casts
Reproducing the mistake:
:appBar (m/AppBar :title "this is an invalid way")
In the documentation, :title
expects a Text widget.
The compiler does not emitting any errors, instead, it casts the string to a Widget, knowing that the cast won't work.
Suggestion: not doing the cast and emit an error at compile time
I actually get the expected error:
Error: Expected a value of type 'Widget?', but got one of type 'String'
at Object.throw_ [as throw] (http://localhost:50992/dart_sdk.js:5067:11)
at Object.castError (http://localhost:50992/dart_sdk.js:5026:15)
@nrfm what @NaadiQmmr is complaining about is that she gets a runtime error while it could have been a compilation error.
The hard thing is deciding when to raise this error. Some classes (like String) can't be extended so for them it's easy. For constructors call too. But in general we must not crash just because a type hint appears incompatible. As a later def type may fill the gap.
A warning may be enough.
With possibly a ^:dont-warn
... or be stricter in general and have a ^:trust-in-me
for casts which seems wrong.
Ah. I get it. Thanks for the explanation.