mirror of
https://github.com/dart-lang/sdk
synced 2024-09-18 22:01:19 +00:00
[dart2js] Update MethodTypeInformation to narrow the return type of
_lateReadCheck. Change-Id: If76a5b34cfd9da9721bfa0d8642b018a4af131dd Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/213901 Reviewed-by: Stephen Adams <sra@google.com> Commit-Queue: Mayank Patke <fishythefish@google.com>
This commit is contained in:
parent
9872fd192e
commit
35421c5d1a
|
@ -625,6 +625,9 @@ class MethodTypeInformation extends MemberTypeInformation {
|
|||
@override
|
||||
AbstractValue _potentiallyNarrowType(
|
||||
AbstractValue mask, InferrerEngine inferrer) {
|
||||
if (inferrer.commonElements.isLateReadCheck(_method)) {
|
||||
mask = inferrer.abstractValueDomain.excludeLateSentinel(mask);
|
||||
}
|
||||
return _narrowType(inferrer.closedWorld, mask, _type.returnType);
|
||||
}
|
||||
|
||||
|
|
36
pkg/compiler/test/codegen/late_test.dart
Normal file
36
pkg/compiler/test/codegen/late_test.dart
Normal file
|
@ -0,0 +1,36 @@
|
|||
// Copyright (c) 2021, 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.
|
||||
|
||||
import 'dart:async';
|
||||
import 'package:async_helper/async_helper.dart';
|
||||
import '../helpers/compiler_helper.dart';
|
||||
|
||||
const String TEST = r"""
|
||||
class Foo {
|
||||
late int x;
|
||||
}
|
||||
|
||||
int foo() {
|
||||
final foo = Foo();
|
||||
foo.x = 40;
|
||||
return foo.x + 2;
|
||||
// present: '+ 2'
|
||||
// absent: 'add'
|
||||
}
|
||||
""";
|
||||
|
||||
Future check(String test) {
|
||||
return compile(test,
|
||||
entry: 'foo',
|
||||
check: checkerForAbsentPresent(test),
|
||||
disableTypeInference: false,
|
||||
disableInlining: false,
|
||||
soundNullSafety: true);
|
||||
}
|
||||
|
||||
void main() {
|
||||
asyncTest(() async {
|
||||
await check(TEST);
|
||||
});
|
||||
}
|
Loading…
Reference in a new issue