|
| 1 | +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +/// @assertion - Method invocation: If `N` is an expression of the form |
| 6 | +/// `E1.m1(E2)`, then: |
| 7 | +/// - Let `before(E1) = before(N)` |
| 8 | +/// - Let `before(E2) = after(E1)` |
| 9 | +/// - Let `T` be the static return type of the invocation |
| 10 | +/// - If `T <: Never` then: |
| 11 | +/// - Let `after(N) = unreachable(after(E2))`. |
| 12 | +/// - Otherwise: |
| 13 | +/// - Let `after(N) = after(E2)`. |
| 14 | +/// |
| 15 | +/// @description Checks that for an expression of the form `E1.m1(E2)`, if the |
| 16 | +/// static type of `E1` is not `Never` then `after(N) = after(E2)`. This is |
| 17 | +/// tested by detecting that `i = 42` is considered to be guaranteed to have |
| 18 | +/// been executed when `i;` is executed. Test the case when `m1` is a getter |
| 19 | +/// returning a function type. |
| 20 | + |
| 21 | +
|
| 22 | +class C { |
| 23 | + void Function(int) get foo => (int x) {}; |
| 24 | + void Function([int]) get bar => ([int x = 0]) {}; |
| 25 | + void Function({int x}) get baz => ({int x = 0}) {}; |
| 26 | + void Function({required int x}) get qux => ({required int x}) {}; |
| 27 | +} |
| 28 | + |
| 29 | +void test1() { |
| 30 | + int i; |
| 31 | + C().foo(i = 42); |
| 32 | + i; // Definitely assigned |
| 33 | +} |
| 34 | + |
| 35 | +void test2() { |
| 36 | + int i; |
| 37 | + C().bar(i = 42); |
| 38 | + i; // Definitely assigned |
| 39 | +} |
| 40 | + |
| 41 | +void test3() { |
| 42 | + int i; |
| 43 | + C().baz(x: i = 42); |
| 44 | + i; // Definitely assigned |
| 45 | +} |
| 46 | + |
| 47 | +void test4() { |
| 48 | + int i; |
| 49 | + C().qux(x: i = 42); |
| 50 | + i; // Definitely assigned |
| 51 | +} |
| 52 | + |
| 53 | +main() { |
| 54 | + test1(); |
| 55 | + test2(); |
| 56 | + test3(); |
| 57 | + test4(); |
| 58 | +} |
0 commit comments