From 34ebfc6594bf6efb187c0ffd9badc9e5c4bdbfb1 Mon Sep 17 00:00:00 2001 From: Mayank Patke Date: Tue, 10 May 2022 22:56:23 +0000 Subject: [PATCH] [dart2js] Add regression test for https://dart-review.googlesource.com/c/sdk/+/225320 Change-Id: Iff348b9ce13ea249b8c63f8c0952cd446ad5cb7d Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/243528 Commit-Queue: Mayank Patke Reviewed-by: Sigmund Cherem --- .../test/inference/data/late_field.dart | 21 +++++++++++++++++++ tests/web/late_no_inlining_test.dart | 21 +++++++++++++++++++ 2 files changed, 42 insertions(+) create mode 100644 pkg/compiler/test/inference/data/late_field.dart create mode 100644 tests/web/late_no_inlining_test.dart diff --git a/pkg/compiler/test/inference/data/late_field.dart b/pkg/compiler/test/inference/data/late_field.dart new file mode 100644 index 00000000000..678b890e174 --- /dev/null +++ b/pkg/compiler/test/inference/data/late_field.dart @@ -0,0 +1,21 @@ +// Copyright (c) 2022, 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. + +import 'package:compiler/src/util/testing.dart'; + +/*member: Foo.:[exact=Foo]*/ +class Foo { + /*member: Foo._#Foo#x:[sentinel|exact=JSUInt31]*/ + /*member: Foo.x:[exact=JSUInt31]*/ + late int /*[exact=Foo]*/ /*update: [exact=Foo]*/ x = 42; +} + +/*member: main:[null]*/ +void main() { + makeLive(test(Foo())); +} + +@pragma('dart2js:noInline') +/*member: test:[exact=JSUInt31]*/ +int test(Foo /*[exact=Foo]*/ foo) => foo. /*[exact=Foo]*/ x; diff --git a/tests/web/late_no_inlining_test.dart b/tests/web/late_no_inlining_test.dart new file mode 100644 index 00000000000..d6814f4b3e8 --- /dev/null +++ b/tests/web/late_no_inlining_test.dart @@ -0,0 +1,21 @@ +// Copyright (c) 2022, 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. + +// dart2jsOptions=--disable-inlining + +import 'package:expect/expect.dart'; + +// Tests to ensure that narrowing type information does not discard late +// sentinel values unintentionally. + +class Foo { + late int bar = 42; + late final int baz = 1729; +} + +void main() { + final foo = Foo(); + Expect.equals(42, foo.bar); + Expect.equals(1729, foo.baz); +}