dart-sdk/tests/language/regress/regress31436_test.dart
Johnni Winther ad9c73cb32 [cfe] Use promoted type as type context in variable assignment
Closes #41698

Change-Id: Iea87c770b560f6f72f9382f06615d99ad2be0c3a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/155764
Commit-Queue: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Paul Berry <paulberry@google.com>
2020-08-03 10:37:41 +00:00

67 lines
1.8 KiB
Dart

// Copyright (c) 2017, 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";
void block_test() {
List<Object> Function() g;
g = () {
return [3];
};
Expect.isTrue(g is List<Object> Function());
Expect.isFalse(g is List<int> Function());
g().add("hello"); // No runtime error
List<int> l = [3];
g = () {
return l;
};
Expect.isTrue(g is List<Object> Function());
Expect.isTrue(g is List<int> Function());
Expect.throwsTypeError(() {
g().add("hello"); // runtime error
});
dynamic o = l;
g = () {
return o;
}; // No implicit downcast on the assignment, implicit downcast on the return
Expect.isTrue(g is List<Object> Function());
Expect.isFalse(g is List<int> Function());
Expect.isTrue(g is Object Function());
g(); // No runtime error;
o = 3;
Expect.throwsTypeError(() {
g(); // Failed runtime cast on the return type of f
});
}
void arrow_test() {
List<Object> Function() g;
g = () => [3];
Expect.isTrue(g is List<Object> Function());
Expect.isFalse(g is List<int> Function());
g().add("hello"); // No runtime error
List<int> l = [3];
g = () => l;
Expect.isTrue(g is List<Object> Function());
Expect.isTrue(g is List<int> Function());
Expect.throwsTypeError(() {
g().add("hello"); // runtime error
});
dynamic o = l;
g = () =>
o; // No implicit downcast on the assignment, implicit downcast on the return
Expect.isTrue(g is List<Object> Function());
Expect.isFalse(g is List<int> Function());
Expect.isTrue(g is Object Function());
g(); // No runtime error;
o = 3;
Expect.throwsTypeError(() {
g(); // Failed runtime cast on the return type of f
});
}
main() {
block_test();
arrow_test();
}