diff --git a/TypeSystem/flow-analysis/type_of_interest_A01_t01.dart b/TypeSystem/flow-analysis/type_of_interest_A01_t01.dart new file mode 100644 index 0000000000..1831fec3ba --- /dev/null +++ b/TypeSystem/flow-analysis/type_of_interest_A01_t01.dart @@ -0,0 +1,24 @@ +// Copyright (c) 2025, 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. + +/// @assertion We say that at type `T` is a type of interest for a variable `x` +/// in a set of tested types `tested` if `tested` contains a type `S` such that +/// `T` is `S`, or `T` is `NonNull(S)`. +/// +/// @description Checks that `x is T` makes `T` a type of interest for `x`. +/// @author sgrekhov22@gmail.com +/// @issue 60479 + +class S {} + +class T extends S { + int foo() => 42; +} + +main() { + S x = S(); + x is T; // make `T` a type of interest + x = T(); + x.foo(); +} diff --git a/TypeSystem/flow-analysis/type_of_interest_A01_t02.dart b/TypeSystem/flow-analysis/type_of_interest_A01_t02.dart new file mode 100644 index 0000000000..471b58a0c2 --- /dev/null +++ b/TypeSystem/flow-analysis/type_of_interest_A01_t02.dart @@ -0,0 +1,33 @@ +// Copyright (c) 2025, 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. + +/// @assertion We say that at type `T` is a type of interest for a variable `x` +/// in a set of tested types `tested` if `tested` contains a type `S` such that +/// `T` is `S`, or `T` is `NonNull(S)`. +/// +/// @description Checks that `x is T` makes `T` a type of interest for `x`. +/// @author sgrekhov22@gmail.com + +class S {} + +class T extends S { + int foo() => 42; +} + +test1(S s) { + if (s is T) {} // make `T` a type of interest + s = T(); + s.foo(); +} + +test2(S? s) { + if (s is T) {} + s = T(); + s.foo(); +} + +main() { + test1(S()); + test2(S()); +} diff --git a/TypeSystem/flow-analysis/type_of_interest_A01_t03.dart b/TypeSystem/flow-analysis/type_of_interest_A01_t03.dart new file mode 100644 index 0000000000..b7c2fd20f4 --- /dev/null +++ b/TypeSystem/flow-analysis/type_of_interest_A01_t03.dart @@ -0,0 +1,40 @@ +// Copyright (c) 2025, 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. + +/// @assertion We say that at type `T` is a type of interest for a variable `x` +/// in a set of tested types `tested` if `tested` contains a type `S` such that +/// `T` is `S`, or `T` is `NonNull(S)`. +/// +/// @description Checks that `x is T?` makes `T` a type of interest for `x`. +/// @author sgrekhov22@gmail.com + +class S {} + +class T extends S { + int foo() => 42; +} + +test1(S? s) { + if (s is T?) {} // make `T?` and `T` types of interest + s = T(); + s.foo(); +} + +test2(S? s) { + if (s is T?) {} + s = 1 > 2 ? null: T(); // assign `T?` to `s` + s?.foo(); +} + +test3(S s) { + if (s is T?) {} + s = T(); + s.foo(); +} + +main() { + test1(S()); + test2(S()); + test3(S()); +} diff --git a/TypeSystem/flow-analysis/type_of_interest_A01_t04.dart b/TypeSystem/flow-analysis/type_of_interest_A01_t04.dart new file mode 100644 index 0000000000..c80bd1d64d --- /dev/null +++ b/TypeSystem/flow-analysis/type_of_interest_A01_t04.dart @@ -0,0 +1,30 @@ +// Copyright (c) 2025, 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. + +/// @assertion We say that at type `T` is a type of interest for a variable `x` +/// in a set of tested types `tested` if `tested` contains a type `S` such that +/// `T` is `S`, or `T` is `NonNull(S)`. +/// +/// @description Checks that if `T` is a type of interest for a variable `x`, +/// then it doesn't make `T?` a type of interest for `x`. +/// @author sgrekhov22@gmail.com + +class S {} + +class T extends S { + int foo() => 42; +} + +test(S? s) { + if (s is T) {} + s = 1 > 2 ? null: T(); // assign `T?` to `s` + s?.foo(); +// ^^^ +// [analyzer] unspecified +// [cfe] unspecified +} + +main() { + print(test); +} diff --git a/TypeSystem/flow-analysis/type_of_interest_A02_t01.dart b/TypeSystem/flow-analysis/type_of_interest_A02_t01.dart new file mode 100644 index 0000000000..94d4c45356 --- /dev/null +++ b/TypeSystem/flow-analysis/type_of_interest_A02_t01.dart @@ -0,0 +1,35 @@ +// Copyright (c) 2025, 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. + +/// @assertion We say that at type `T` is a type of interest for a variable `x` +/// in a set of tested types `tested` if `tested` contains a type `S` such that +/// `T` is `S`, or `T` is `NonNull(S)`. +/// +/// @description Checks that `x is! T` makes `T` a type of interest for `x`. +/// @author sgrekhov22@gmail.com +/// @issue 60479 + +class S {} + +class T extends S { + int foo() => 42; +} + +test1() { + S s = S(); + s is! T; // Make `T` a type of interest + s = T(); + s.foo(); +} + +test2(S? s) { + if (s is! T?) {} + s = T(); + s.foo(); +} + +main() { + test1(); + test2(S()); +}