mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 22:01:19 +00:00
e933e91aaa
This is a reland of 6a1c54ec30
Original change's description:
> Flow analysis: promote to non-nullable on initialization
>
> When flow analysis encounters a variable declaration of the form `T? x
> = expr;`, if the type of `expr` is `T`, then the variable is
> immediately promoted to type `T`.
>
> Fixes #43099.
>
> Change-Id: Ia206fe0d50e2fdd9bdf637e13c85633d8490dbcc
> Bug: https://github.com/dart-lang/sdk/issues/43099
> Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/163841
> Commit-Queue: Paul Berry <paulberry@google.com>
> Reviewed-by: Bob Nystrom <rnystrom@google.com>
> Reviewed-by: Johnni Winther <johnniwinther@google.com>
> Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Bug: https://github.com/dart-lang/sdk/issues/43099
Change-Id: I7530bb0f7c24674a7b500558b89d50b35e045aca
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/166305
Reviewed-by: Johnni Winther <johnniwinther@google.com>
Reviewed-by: Konstantin Shcheglov <scheglov@google.com>
Commit-Queue: Paul Berry <paulberry@google.com>
24 lines
541 B
Dart
24 lines
541 B
Dart
// Copyright (c) 2015, 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.
|
|
|
|
// Regression test for issue dartbug.com/24392
|
|
|
|
import 'package:expect/expect.dart';
|
|
import 'dart:async';
|
|
|
|
Future<int?> f() async {
|
|
// Unreachable.
|
|
Expect.isTrue(false);
|
|
}
|
|
|
|
main() async {
|
|
var x = 1 as int?;
|
|
x ??= await f();
|
|
Expect.equals(1, x);
|
|
|
|
var y = 1 as int?;
|
|
y = y ?? await f();
|
|
Expect.equals(1, y);
|
|
}
|