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
36 changes: 36 additions & 0 deletions LanguageFeatures/Patterns/type_inference_A04_t03.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright (c) 2023, 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
/// The context type schema for a pattern p is:
/// ...
/// Identifier:
/// In an assignment context, the context type schema is the static type of the
/// variable that p resolves to.
///
/// Else the context type schema is _
///
/// @description Check that in an assignment context, the context type schema is
/// the static type of the variable that p resolves to. Test promoted type
/// @author [email protected]

// SharedOptions=--enable-experiment=patterns,records

main() {
num a = 0;
a as int;
a.isEven;
[a] = [3.14]; // [a] infers <int>[3.14] to right hand expression
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified

var c = 2 > 1 ? 42 : 3.14;
c as int;
c.isEven;
{"key1": c} = {"key1": 3.14};
// ^^^^
// [analyzer] unspecified
// [cfe] unspecified
}
6 changes: 3 additions & 3 deletions LanguageFeatures/Patterns/type_inference_A26_t01.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@ main() {
num a = 0;
a as int;
a.isEven;
[a] = [3.14];
[a] = <double>[3.14];
a.expectStaticType<Exactly<num>>();

var (num b,) = (0,);
b as int;
b.isEven;
(b,) = (3.14,);
b.expectStaticType<Exactly<num>>();
a.expectStaticType<Exactly<num>>();

var c = 2 > 1 ? 42 : 3.14;
c.expectStaticType<Exactly<num>>();
c as int;
c.isEven;
{"key1": c} = {"key1": 3.14};
{"key1": c} = <String, double>{"key1": 3.14};
c.expectStaticType<Exactly<num>>();
}