Skip to content

Commit

Permalink
dart-lang#3057. Add instance check tests
Browse files Browse the repository at this point in the history
  • Loading branch information
sgrekhov committed Feb 14, 2025
1 parent 362f338 commit 3ff8570
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 0 deletions.
26 changes: 26 additions & 0 deletions TypeSystem/flow-analysis/reachability_A12_t01.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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 instance check If `N` is an expression of the form `E1 is S`
/// where the static type of `E1` is `T` then:
/// - Let `before(E1) = before(N)`
/// - Let `true(N) = promote(E1, S, after(E1))`
/// - Let `false(N) = promote(E1, factor(T, S), after(E1))`
///
/// @description Checks that for expression of the form `E1 is S`
/// `true(N) = promote(E1, S, after(E1))` and
/// `false(N) = promote(E1, factor(T, S), after(E1))`. Test `factor(T, S)` for
/// the case `T` is `R?` and `Null <: S`.
/// @author [email protected]
main() {
int? i = 2 > 1 ? null : 42;
if (i is Null) {
Null n = i; // Ok
int j = i;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
}
26 changes: 26 additions & 0 deletions TypeSystem/flow-analysis/reachability_A12_t02.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// 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 instance check If `N` is an expression of the form `E1 is S`
/// where the static type of `E1` is `T` then:
/// - Let `before(E1) = before(N)`
/// - Let `true(N) = promote(E1, S, after(E1))`
/// - Let `false(N) = promote(E1, factor(T, S), after(E1))`
///
/// @description Checks that for expression of the form `E1 is S`
/// `true(N) = promote(E1, S, after(E1))` and
/// `false(N) = promote(E1, factor(T, S), after(E1))`. Test `factor(T, S)` for
/// the case `T` is `R?` and `Null <: S`.
/// @author [email protected]
main() {
int? i = 2 > 1 ? null : 42;
if (i is int) {
int j = i;
Null n = i;
// ^
// [analyzer] unspecified
// [cfe] unspecified
}
}
34 changes: 34 additions & 0 deletions TypeSystem/flow-analysis/reachability_A12_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
// 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 instance check If `N` is an expression of the form `E1 is S`
/// where the static type of `E1` is `T` then:
/// - Let `before(E1) = before(N)`
/// - Let `true(N) = promote(E1, S, after(E1))`
/// - Let `false(N) = promote(E1, factor(T, S), after(E1))`
///
/// @description Checks that for expression of the form `E1 is S`
/// `true(N) = promote(E1, S, after(E1))` and
/// `false(N) = promote(E1, factor(T, S), after(E1))`. Test `factor(T, S)` for
/// the case `T` is `FutureOr<R>` and `Future<R> <: S`.
/// @author [email protected]
import 'dart:async';

class C {
void foo() {}
}

test(FutureOr<C> foc) async {
if (foc is Future<C>) {
foc.foo();
// ^^^
// [analyzer] unspecified
// [cfe] unspecified
}
}

main() {
print(test);
}
32 changes: 32 additions & 0 deletions TypeSystem/flow-analysis/reachability_A12_t04.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// 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 instance check If `N` is an expression of the form `E1 is S`
/// where the static type of `E1` is `T` then:
/// - Let `before(E1) = before(N)`
/// - Let `true(N) = promote(E1, S, after(E1))`
/// - Let `false(N) = promote(E1, factor(T, S), after(E1))`
///
/// @description Checks that for expression of the form `E1 is S`
/// `true(N) = promote(E1, S, after(E1))` and
/// `false(N) = promote(E1, factor(T, S), after(E1))`. Test `factor(T, S)` for
/// the case `T` is `FutureOr<R>` and `R <: S`.
/// @author [email protected]
import 'dart:async';

class C {
void foo() {}
}

test(FutureOr<C> foc) async {
if (foc is C) {
foc.foo(); // Ok
}
}

main() {
test(C());
test(Future<C>.value(C()));
}

0 comments on commit 3ff8570

Please sign in to comment.