dart-sdk/tests/standalone/array_bounds_check_generalization_test.dart
Liam Appelbe 87b829bacd [nnbd] Fix some more strong mode tests
All these tests now pass in both weak and strong mode, except for
relation_subclass_test and typedef_reflected_type_test. For those 2
tests I fixed the compile time error and now they have the same runtime
errors in both weak and strong mode (they were already failing at
runtime in weak mode).

Change-Id: If0157f811fffcf72a12ce6690ac0568c8f4419a9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/144343
Commit-Queue: Liam Appelbe <liama@google.com>
Reviewed-by: Régis Crelier <regis@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
2020-04-22 00:12:24 +00:00

89 lines
2 KiB
Dart

// Copyright (c) 2012, 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.
//
// We are using --complete-timeline below to ensure that we get timeline events
// generated during all phases of compilation and deoptimization.
// VMOptions=--optimization_counter_threshold=10 --no-use-osr --complete-timeline --no-background_compilation
import "package:expect/expect.dart";
test1(a, start, step, N) {
var e;
for (var i = 0; i < N; i++) {
e = a[start + i * step];
}
return e;
}
test2(a, b) {
var e;
for (var i = 0, j = 0, k = 0; i < a.length; i++, j++, k++) {
e = b[k] = a[j];
}
return e;
}
test3(a, b) {
var e;
for (var i = 0, j = 1, k = 0; i < a.length - 1; i++, j++, k++) {
e = b[k] = a[j - 1];
}
return e;
}
test4(a, b) {
var e;
if (a.length < 2) {
return null;
}
for (var i = 0, j = 1, k = 0; i < a.length - 1; i++, j++, k++) {
e = b[k] = a[j - 1];
}
return e;
}
test5(a, b, k0) {
var e;
if (a.length < 2) {
return null;
}
if (k0 > 1) {
return null;
}
for (var i = 0, j = 1, k = 0; i < a.length - 1; i++, j++, k++) {
e = b[k - k0] = a[j - 1];
}
return e;
}
test6(List<int> a, int M, int N) {
var e = 0;
for (var i = 0; i < N; i++) {
for (var j = 0; j < M; j++) {
e += a[i * M + j];
}
}
return e;
}
main() {
var a = const [0, 1, 2, 3, 4, 5, 6, 7];
var b = List.filled(a.length, -1);
for (var i = 0; i < 10000; i++) {
Expect.equals(a.last, test1(a, 0, 1, a.length));
Expect.equals(a.last, test2(a, b));
Expect.equals(a[a.length - 2], test3(a, b));
Expect.equals(a[a.length - 2], test4(a, b));
Expect.equals(a[a.length - 2], test5(a, b, 0));
Expect.equals(6, test6(a, 2, 2));
}
test1(a, 0, 2, a.length ~/ 2);
Expect.throws(() => test1(a, 1, 1, a.length));
Expect.throws(() => test2(a, List.filled(a.length - 1, -1)));
Expect.throws(() => test6(a, 4, 3));
}