dart-sdk/tests/web_2/regress_40349_test.dart
Sigmund Cherem 912005267d [web] rename suite dart2js -> web.
Change-Id: I46be49b2effec3e38a3dc44cd45cfe736f77fa78
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/182680
Commit-Queue: Sigmund Cherem <sigmund@google.com>
Reviewed-by: Joshua Litt <joshualitt@google.com>
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Stephen Adams <sra@google.com>
2021-02-04 23:11:32 +00:00

45 lines
1.4 KiB
Dart

// Copyright (c) 2020, 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.
// @dart = 2.7
/// Regression test for Issue #40349:
///
/// Before the fix, this code was accidentally generating a type check twice.
/// In between the two checks, code to update `_foo` was overriding a temporary
/// variable used by the check subexpression, which made the code for the
/// second check invalid.
///
/// The second check should not have been generated, but it was emitted due to
/// a broken invariant of the SSA generate-at-use logic.
void main() {
// `x` which is used multiple times after inilining, so a temporary is used.
x.method(40);
}
dynamic x = Wrapper<int>();
class A<E> {
int _foo = 0;
List<E> list = [null];
@pragma('dart2js:tryInline')
void internalMethod(E value) {
// The update and use of `_foo` requires a separate temporary which reuses
// the same variable given to `x` (technically `x` is no longer live).
_foo = (_foo + 1) & 0;
// This use of `value` accidentally contains the second check, which
// still refers to the temporary assuming it was `x` and not `_foo`.
list[_foo] = value;
}
}
class Wrapper<T> {
A<T> a = A<T>();
@pragma('dart2js:tryInline')
method(T t) => a.internalMethod(t);
}