Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions TypeSystem/flow-analysis/type_of_interest_A01_t01.dart
Original file line number Diff line number Diff line change
@@ -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();
}
33 changes: 33 additions & 0 deletions TypeSystem/flow-analysis/type_of_interest_A01_t02.dart
Original file line number Diff line number Diff line change
@@ -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());
}
40 changes: 40 additions & 0 deletions TypeSystem/flow-analysis/type_of_interest_A01_t03.dart
Original file line number Diff line number Diff line change
@@ -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());
}
30 changes: 30 additions & 0 deletions TypeSystem/flow-analysis/type_of_interest_A01_t04.dart
Original file line number Diff line number Diff line change
@@ -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);
}
35 changes: 35 additions & 0 deletions TypeSystem/flow-analysis/type_of_interest_A02_t01.dart
Original file line number Diff line number Diff line change
@@ -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());
}