dart - DartPad allows string iteration -
i'd know why code below prints each letter of test
on dartpad, , throws exception on terminal. mean, strings in dart not iterable, don't understand how works on dartpad; i'd expect exception there well. ideias?
void main() { var test = 'test'; (var t in test) { print(t); } }
i tested dart 1.14.0, happening in previous versions well.
i guess because dart converted javascript , javascript supports iterating on strings , performance reasons there no additional checks prevent it.
what imho bug, analyzer doesn't show warning, when test
explicitely typed string
void main() { string test = 'test'; (var t in test) { print(t); } }
when enable strong-mode, warning though.
my_project/.analysis_options
analyzer: strong-mode: true
type check failed: test (string) not of type iterable
for both
var test = 'test'; // or string test = 'test';
Comments
Post a Comment