Skip to content

Commit 7b4f3e7

Browse files
authored
Fixes #1878. Fix type inference in type_inference_A26_t01.dart (#1892)
1 parent 40ae4df commit 7b4f3e7

File tree

2 files changed

+39
-3
lines changed

2 files changed

+39
-3
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
// Copyright (c) 2023, 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
6+
/// The context type schema for a pattern p is:
7+
/// ...
8+
/// Identifier:
9+
/// In an assignment context, the context type schema is the static type of the
10+
/// variable that p resolves to.
11+
///
12+
/// Else the context type schema is _
13+
///
14+
/// @description Check that in an assignment context, the context type schema is
15+
/// the static type of the variable that p resolves to. Test promoted type
16+
/// @author [email protected]
17+
18+
// SharedOptions=--enable-experiment=patterns,records
19+
20+
main() {
21+
num a = 0;
22+
a as int;
23+
a.isEven;
24+
[a] = [3.14]; // [a] infers <int>[3.14] to right hand expression
25+
// ^^^^
26+
// [analyzer] unspecified
27+
// [cfe] unspecified
28+
29+
var c = 2 > 1 ? 42 : 3.14;
30+
c as int;
31+
c.isEven;
32+
{"key1": c} = {"key1": 3.14};
33+
// ^^^^
34+
// [analyzer] unspecified
35+
// [cfe] unspecified
36+
}

LanguageFeatures/Patterns/type_inference_A26_t01.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,19 @@ main() {
2828
num a = 0;
2929
a as int;
3030
a.isEven;
31-
[a] = [3.14];
31+
[a] = <double>[3.14];
3232
a.expectStaticType<Exactly<num>>();
3333

3434
var (num b,) = (0,);
3535
b as int;
3636
b.isEven;
3737
(b,) = (3.14,);
38-
b.expectStaticType<Exactly<num>>();
38+
a.expectStaticType<Exactly<num>>();
3939

4040
var c = 2 > 1 ? 42 : 3.14;
4141
c.expectStaticType<Exactly<num>>();
4242
c as int;
4343
c.isEven;
44-
{"key1": c} = {"key1": 3.14};
44+
{"key1": c} = <String, double>{"key1": 3.14};
4545
c.expectStaticType<Exactly<num>>();
4646
}

0 commit comments

Comments
 (0)