[dart2js] add regression test for issue 48571
Global type inference incorrectly handles conditions nested within subexpressions and accidentally carries information from those in the context of outer conditions. Change-Id: I99e0af3da65590acb9429771b318b7da8f3b7f14 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/240320 Reviewed-by: Stephen Adams <sra@google.com>
This commit is contained in:
committed by
Commit Bot
parent
0a74c76773
commit
bbf5dc1c59
@@ -0,0 +1,83 @@
|
||||
// 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.
|
||||
|
||||
/*member: Base.:[subclass=Base]*/
|
||||
abstract class Base {}
|
||||
|
||||
/*member: Child1.:[exact=Child1]*/
|
||||
class Child1 extends Base {}
|
||||
|
||||
/*member: Child2.:[exact=Child2]*/
|
||||
class Child2 extends Base {}
|
||||
|
||||
/*member: trivial:Value([exact=JSBool], value: true)*/
|
||||
bool trivial(/*[exact=JSBool]*/ x) => true;
|
||||
|
||||
/*member: either:Union([exact=Child1], [exact=Child2])*/
|
||||
Base either = DateTime.now()
|
||||
. /*[exact=DateTime]*/ millisecondsSinceEpoch /*invoke: [subclass=JSInt]*/ >
|
||||
0
|
||||
? Child2()
|
||||
: Child1();
|
||||
|
||||
/*member: test1:[null|exact=Child1]*/
|
||||
test1() {
|
||||
Base child = either;
|
||||
if (trivial(child is Child1 && true)) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
/*member: test2:[null|exact=Child1]*/
|
||||
test2() {
|
||||
Base child = either;
|
||||
if (child is Child1 || trivial(child is Child1 && true)) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
/*member: test3:[null]*/
|
||||
test3() {
|
||||
Base child = either;
|
||||
if (trivial(child is Child1 && true) && child is Child2) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
/*member: test4:[null]*/
|
||||
test4() {
|
||||
Base child = either;
|
||||
if (child is Child2 && trivial(child is Child1 && true)) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
/*member: test5:[null|exact=Child1]*/
|
||||
test5() {
|
||||
Base child = either;
|
||||
if ((child is Child1 && true) /*invoke: [exact=JSBool]*/ == false)
|
||||
return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
/*member: test6:Union(null, [exact=Child1], [exact=Child2])*/
|
||||
test6() {
|
||||
Base child = either;
|
||||
if (trivial(child is Child1 ? false : true)) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
/*member: test7:[null|exact=Child1]*/
|
||||
test7() {
|
||||
Base child = either;
|
||||
if (trivial(trivial(child is Child1 && true))) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
/*member: main:[null]*/
|
||||
main() {
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
test5();
|
||||
test6();
|
||||
test7();
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
// 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:expect/expect.dart';
|
||||
|
||||
abstract class Base {}
|
||||
|
||||
class Child1 extends Base {}
|
||||
|
||||
class Child2 extends Base {}
|
||||
|
||||
bool trivial(x) => true;
|
||||
Base either = DateTime.now().millisecondsSinceEpoch > 0 ? Child2() : Child1();
|
||||
|
||||
test1() {
|
||||
Base child = either;
|
||||
if (trivial(child is Child1 && true)) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
test2() {
|
||||
Base child = either;
|
||||
if (child is Child1 || trivial(child is Child1 && true)) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
test3() {
|
||||
Base child = either;
|
||||
if (trivial(child is Child1 && true) && child is Child2) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
test4() {
|
||||
Base child = either;
|
||||
if (child is Child2 && trivial(child is Child1 && true)) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
test5() {
|
||||
Base child = either;
|
||||
if ((child is Child1 && true) == false) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
test6() {
|
||||
Base child = either;
|
||||
if (trivial(child is Child1 ? false : true)) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
test7() {
|
||||
Base child = either;
|
||||
if (trivial(trivial(child is Child1 && true))) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
main() {
|
||||
Expect.isTrue(test1() is Child2, "test1");
|
||||
Expect.isTrue(test2() is Child2, "test2");
|
||||
Expect.isTrue(test3() is Child2, "test3");
|
||||
Expect.isTrue(test4() is Child2, "test4");
|
||||
Expect.isTrue(test5() is Child2, "test5");
|
||||
Expect.isTrue(test6() is Child2, "test6");
|
||||
Expect.isTrue(test7() is Child2, "test7");
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
// 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.
|
||||
|
||||
// @dart = 2.7
|
||||
|
||||
import 'package:expect/expect.dart';
|
||||
|
||||
abstract class Base {}
|
||||
|
||||
class Child1 extends Base {}
|
||||
|
||||
class Child2 extends Base {}
|
||||
|
||||
bool trivial(x) => true;
|
||||
Base either = DateTime.now().millisecondsSinceEpoch > 0 ? Child2() : Child1();
|
||||
|
||||
test1() {
|
||||
Base child = either;
|
||||
if (trivial(child is Child1 && true)) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
test2() {
|
||||
Base child = either;
|
||||
if (child is Child1 || trivial(child is Child1 && true)) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
test3() {
|
||||
Base child = either;
|
||||
if (trivial(child is Child1 && true) && child is Child2) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
test4() {
|
||||
Base child = either;
|
||||
if (child is Child2 && trivial(child is Child1 && true)) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
test5() {
|
||||
Base child = either;
|
||||
if ((child is Child1 && true) == false) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
test6() {
|
||||
Base child = either;
|
||||
if (trivial(child is Child1 ? false : true)) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
test7() {
|
||||
Base child = either;
|
||||
if (trivial(trivial(child is Child1 && true))) return child;
|
||||
return null;
|
||||
}
|
||||
|
||||
main() {
|
||||
Expect.isTrue(test1() is Child2, "test1");
|
||||
Expect.isTrue(test2() is Child2, "test2");
|
||||
Expect.isTrue(test3() is Child2, "test3");
|
||||
Expect.isTrue(test4() is Child2, "test4");
|
||||
Expect.isTrue(test5() is Child2, "test5");
|
||||
Expect.isTrue(test6() is Child2, "test6");
|
||||
Expect.isTrue(test7() is Child2, "test7");
|
||||
}
|
||||
Reference in New Issue
Block a user