c7e6c98877
This CL adds implementation of the static analysis of anonymous methods whose body is of the form `=> e`. Block bodies are still rejected by a `UnimplementedError` exception. Flow analysis is rudimentary, but this might be sufficiuent for the particular kind of anonymous methods which are covered by this CL. In particular, it does not cause assigned local variables to be marked as non-promotable in enclosing scopes, and it does allow local variables promoted in the anonymous method body to preserve their promotions after the anonymous method invocation. Note that the change in `_resolveReceiver` is needed because the old code relied on looking up the syntactically enclosing class or extension in order to determine the type of `this`, but that is incorrect when `this` may be the type of the receiver of an enclosing anonymous method. Change-Id: I3d2bd6d104015a6e310e9ce061c7b4109002a1b2 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/480840 Reviewed-by: Brian Wilkerson <brianwilkerson@google.com> Reviewed-by: Paul Berry <paulberry@google.com> Commit-Queue: Erik Ernst <eernst@google.com>
25 lines
880 B
Dart
25 lines
880 B
Dart
// Copyright (c) 2026, 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.
|
|
|
|
// SharedOptions=--enable-experiment=anonymous-methods
|
|
|
|
import '../../static_type_helper.dart';
|
|
|
|
void context<X>(X _) {}
|
|
|
|
void main() {
|
|
// Verify the context type via its effect on type inference.
|
|
context<List<num>>(''.=> []..expectStaticType<Exactly<List<num>>>);
|
|
context<Future<Pattern>>(
|
|
''.=> Future.value('')..expectStaticType<Exactly<Future<Pattern>>>,
|
|
);
|
|
|
|
// Verify that the context type can give rise to coercions.
|
|
context<int>(''.=> 1..expectStaticType<Exactly<int>>);
|
|
context<double>(''.=> 1..expectStaticType<Exactly<double>>);
|
|
context<void Function(bool)>(
|
|
''.=> context..expectStaticType<Exactly<void Function(bool)>>,
|
|
);
|
|
}
|