mirror of
https://github.com/dart-lang/sdk
synced 2024-09-16 04:16:51 +00:00
30f0e0f4d5
This extends the fix for https://github.com/dart-lang/language/issues/731 (improved inference for fold etc.) to cover situations where the function literal passed to an invocation is enclosed in (unnecessary) parentheses. Change-Id: I5eb40cf73336612e241a930122f8ae7b1c25bb2a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/241021 Reviewed-by: Konstantin Shcheglov <scheglov@google.com> Commit-Queue: Paul Berry <paulberry@google.com>
93 lines
2.3 KiB
Dart
93 lines
2.3 KiB
Dart
// Copyright (c) 2022, 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.
|
|
|
|
// Tests that when the feature is disabled, inferred types do not flow
|
|
// "horizontally" from a non-closure argument of an invocation to a closure
|
|
// argument.
|
|
|
|
// @dart=2.17
|
|
|
|
import '../static_type_helper.dart';
|
|
|
|
testLaterUnnamedParameter(void Function<T>(T, void Function(T)) f) {
|
|
f(0, (x) {
|
|
x.expectStaticType<Exactly<Object?>>();
|
|
});
|
|
}
|
|
|
|
testEarlierUnnamedParameter(void Function<T>(void Function(T), T) f) {
|
|
f((x) {
|
|
x.expectStaticType<Exactly<Object?>>();
|
|
}, 0);
|
|
}
|
|
|
|
testLaterNamedParameter(
|
|
void Function<T>({required T a, required void Function(T) b}) f) {
|
|
f(
|
|
a: 0,
|
|
b: (x) {
|
|
x.expectStaticType<Exactly<Object?>>();
|
|
});
|
|
}
|
|
|
|
testEarlierNamedParameter(
|
|
void Function<T>({required void Function(T) a, required T b}) f) {
|
|
f(
|
|
a: (x) {
|
|
x.expectStaticType<Exactly<Object?>>();
|
|
},
|
|
b: 0);
|
|
}
|
|
|
|
testPropagateToReturnType(U Function<T, U>(T, U Function(T)) f) {
|
|
f(0, (x) => [x]).expectStaticType<Exactly<List<Object?>>>();
|
|
}
|
|
|
|
testUnnecessaryDueToNoDependency(T Function<T>(T Function(), T) f) {
|
|
f(() => 0, null).expectStaticType<Exactly<int?>>();
|
|
}
|
|
|
|
testUnnecessaryDueToExplicitParameterType(List<int> list) {
|
|
var a = list.fold(null, (int? x, y) => (x ?? 0) + y);
|
|
a.expectStaticType<Exactly<int?>>();
|
|
}
|
|
|
|
testUnnecessaryDueToExplicitParameterTypeNamed(
|
|
T Function<T>(T, T Function({required T x, required int y})) f) {
|
|
var a = f(null, ({int? x, required y}) => (x ?? 0) + y);
|
|
a.expectStaticType<Exactly<int?>>();
|
|
}
|
|
|
|
testParenthesized(void Function<T>(T, void Function(T)) f) {
|
|
f(0, ((x) {
|
|
x.expectStaticType<Exactly<Object?>>();
|
|
}));
|
|
}
|
|
|
|
testParenthesizedNamed(
|
|
void Function<T>({required T a, required void Function(T) b}) f) {
|
|
f(
|
|
a: 0,
|
|
b: ((x) {
|
|
x.expectStaticType<Exactly<Object?>>();
|
|
}));
|
|
}
|
|
|
|
testParenthesizedTwice(void Function<T>(T, void Function(T)) f) {
|
|
f(0, (((x) {
|
|
x.expectStaticType<Exactly<Object?>>();
|
|
})));
|
|
}
|
|
|
|
testParenthesizedTwiceNamed(
|
|
void Function<T>({required T a, required void Function(T) b}) f) {
|
|
f(
|
|
a: 0,
|
|
b: (((x) {
|
|
x.expectStaticType<Exactly<Object?>>();
|
|
})));
|
|
}
|
|
|
|
main() {}
|