Add language_2 tests covering some cases of definite assignment.

This CL is intentionally light on coverage, because we put most of
testing in analyzer unit / functional tests.

This CL intentionally does not use multi-tests, because they are
harder to read.

R=brianwilkerson@google.com, paulberry@google.com

Change-Id: Ib48cd02fc93a9d7f8cfa3803d0c51e96c013a99f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/107197
Reviewed-by: Paul Berry <paulberry@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Commit-Queue: Konstantin Shcheglov <scheglov@google.com>
This commit is contained in:
Konstantin Shcheglov 2019-06-25 20:43:24 +00:00 committed by commit-bot@chromium.org
parent 11d369fd58
commit 177f543fa8
8 changed files with 166 additions and 0 deletions

View file

@ -0,0 +1,21 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// SharedOptions=--enable-experiment=non-nullable
// It is an error if a potentially non-nullable local variable which has no
// initializer expression and is not marked `late` is used before it is
// definitely assigned.
f(bool b) {
int v; //# none: compile-time error
if (b) {
// not assigned
} else {
v = 1;
}
v;
}
void main() {}

View file

@ -0,0 +1,21 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// SharedOptions=--enable-experiment=non-nullable
// It is an error if a potentially non-nullable local variable which has no
// initializer expression and is not marked `late` is used before it is
// definitely assigned.
f(bool b) {
int v;
if (b) {
v = 0;
} else {
v = 1;
}
v;
}
void main() {}

View file

@ -0,0 +1,21 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// SharedOptions=--enable-experiment=non-nullable
// It is an error if a potentially non-nullable local variable which has no
// initializer expression and is not marked `late` is used before it is
// definitely assigned.
f(bool b) {
int v; //# none: compile-time error
if (b) {
v = 0;
} else {
// not assigned
}
v;
}
void main() {}

View file

@ -0,0 +1,19 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// SharedOptions=--enable-experiment=non-nullable
// It is an error if a potentially non-nullable local variable which has no
// initializer expression and is not marked `late` is used before it is
// definitely assigned.
f(bool b) {
int v; //# none: compile-time error
if (b) {
v = 0;
}
v;
}
void main() {}

View file

@ -0,0 +1,22 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// SharedOptions=--enable-experiment=non-nullable
// It is an error if a potentially non-nullable local variable which has no
// initializer expression and is not marked `late` is used before it is
// definitely assigned.
void main() {
int v;
try {
g();
v = 0;
} catch (_) {
v = 1;
}
v;
}
void g() {}

View file

@ -0,0 +1,22 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// SharedOptions=--enable-experiment=non-nullable
// It is an error if a potentially non-nullable local variable which has no
// initializer expression and is not marked `late` is used before it is
// definitely assigned.
void main() {
int v; //# none: compile-time error
try {
g();
v = 0;
} catch (_) {
// not assigned
}
v;
}
void g() {}

View file

@ -0,0 +1,20 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// SharedOptions=--enable-experiment=non-nullable
// It is an error if a potentially non-nullable local variable which has no
// initializer expression and is not marked `late` is used before it is
// definitely assigned.
f(bool b) {
int v;
while (true) {
v = 0;
if (b) break;
}
v;
}
void main() {}

View file

@ -0,0 +1,20 @@
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// SharedOptions=--enable-experiment=non-nullable
// It is an error if a potentially non-nullable local variable which has no
// initializer expression and is not marked `late` is used before it is
// definitely assigned.
f(bool b) {
int v; //# none: compile-time error
while (true) {
if (b) break;
v = 0;
}
v;
}
void main() {}