【发布时间】:2021-05-24 15:54:29
【问题描述】:
考虑这个演示:
void test(int? n) {
if (n != null) { // let's make sure n is not null
++n; // ok; n is assumed to be non-null
if (n < 0) {
n = n.abs(); // ok; n is not null in inner scope
}
while (n != 0) {
--n; // error: the method '-' can't be unconditionally invoked because the receiver can be 'null'
}
}
}
为什么n 仍被视为int? 在while(...) { ... } 块内?我正在将 VSCode 与最新版本的 Dart 一起使用。
【问题讨论】:
标签: dart dart-null-safety