Skip to content

Commit e2c17b9

Browse files
chloestefantsovaCommit Queue
authored andcommitted
Enable 'inference-using-bounds' flag in 3.7
TEST=existing Change-Id: If7f143ab6c60cfda962c1ceba78fdbfdd949a3cc Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394140 Reviewed-by: Konstantin Shcheglov <[email protected]> Commit-Queue: Chloe Stefantsova <[email protected]> Reviewed-by: Johnni Winther <[email protected]> Reviewed-by: Slava Egorov <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent baa171d commit e2c17b9

23 files changed

+122
-141
lines changed

pkg/_fe_analyzer_shared/lib/src/experiments/flags.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,10 +140,10 @@ enum ExperimentalFlag {
140140

141141
inferenceUsingBounds(
142142
name: 'inference-using-bounds',
143-
isEnabledByDefault: false,
143+
isEnabledByDefault: true,
144144
isExpired: false,
145-
experimentEnabledVersion: defaultLanguageVersion,
146-
experimentReleasedVersion: defaultLanguageVersion,
145+
experimentEnabledVersion: const Version(3, 7),
146+
experimentReleasedVersion: const Version(3, 7),
147147
),
148148

149149
inlineClass(

pkg/_fe_analyzer_shared/test/inference/inferred_type_arguments/data/constructor_invocation.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,12 @@ staticInvocations() {
5252
ExtendsNum<num> extendsNumReturn3 = ExtendsNum<int>();
5353
ExtendsNum extendsNumReturn4 = ExtendsNum/*<num>*/();
5454

55-
ExtendsNumArg/*<Null>*/(null);
55+
ExtendsNumArg/*<num>*/(null);
5656
ExtendsNumArg/*<int>*/(0);
57-
ExtendsNumArg/*<String>*/("");
57+
ExtendsNumArg/*<num>*/("");
5858
ExtendsNumArg<num>(0);
5959
var extendsNumReturnArg1 = ExtendsNumArg/*<int>*/(0);
60-
var extendsNumReturnArg2 = ExtendsNumArg/*<String>*/("");
60+
var extendsNumReturnArg2 = ExtendsNumArg/*<num>*/("");
6161
ExtendsNumArg<num> extendsNumReturnArg3 = ExtendsNumArg/*<num>*/(0);
6262
ExtendsNumArg<int> extendsNumReturnArg4 = ExtendsNumArg/*<int>*/(0);
6363
ExtendsNumArg<int> extendsNumReturnArg5 = ExtendsNumArg/*<int>*/(0.5);

pkg/_fe_analyzer_shared/test/inference/inferred_type_arguments/data/instance_invocation.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -51,9 +51,9 @@ class Class {
5151
extendsNumUnused/*<num>*/();
5252
extendsNumUnused<int>();
5353

54-
extendsNumArg/*<Null>*/(null);
54+
extendsNumArg/*<num>*/(null);
5555
extendsNumArg/*<int>*/(0);
56-
extendsNumArg/*<String>*/("");
56+
extendsNumArg/*<num>*/("");
5757
extendsNumArg<num>(0);
5858

5959
extendsNumReturn/*<num>*/();
@@ -62,12 +62,12 @@ class Class {
6262
int extendsNumReturn2 = extendsNumReturn/*<int>*/();
6363
num extendsNumReturn3 = extendsNumReturn<int>();
6464

65-
extendsNumReturnArg/*<Null>*/(null);
65+
extendsNumReturnArg/*<num>*/(null);
6666
extendsNumReturnArg/*<int>*/(0);
67-
extendsNumReturnArg/*<String>*/("");
67+
extendsNumReturnArg/*<num>*/("");
6868
extendsNumReturnArg<num>(0);
6969
var extendsNumReturnArg1 = extendsNumReturnArg/*<int>*/(0);
70-
var extendsNumReturnArg2 = extendsNumReturnArg/*<String>*/("");
70+
var extendsNumReturnArg2 = extendsNumReturnArg/*<num>*/("");
7171
num extendsNumReturnArg3 = extendsNumReturnArg/*<num>*/(0);
7272
int extendsNumReturnArg4 = extendsNumReturnArg/*<int>*/(0);
7373
int extendsNumReturnArg5 = extendsNumReturnArg/*<int>*/(0.5);

pkg/_fe_analyzer_shared/test/inference/inferred_type_arguments/data/static_invocation.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ staticInvocations() {
5050
extendsNumUnused/*<num>*/();
5151
extendsNumUnused<int>();
5252

53-
extendsNumArg/*<Null>*/(null);
53+
extendsNumArg/*<num>*/(null);
5454
extendsNumArg/*<int>*/(0);
55-
extendsNumArg/*<String>*/("");
55+
extendsNumArg/*<num>*/("");
5656
extendsNumArg<num>(0);
5757

5858
extendsNumReturn/*<num>*/();
@@ -61,12 +61,12 @@ staticInvocations() {
6161
int extendsNumReturn2 = extendsNumReturn/*<int>*/();
6262
num extendsNumReturn3 = extendsNumReturn<int>();
6363

64-
extendsNumReturnArg/*<Null>*/(null);
64+
extendsNumReturnArg/*<num>*/(null);
6565
extendsNumReturnArg/*<int>*/(0);
66-
extendsNumReturnArg/*<String>*/("");
66+
extendsNumReturnArg/*<num>*/("");
6767
extendsNumReturnArg<num>(0);
6868
var extendsNumReturnArg1 = extendsNumReturnArg/*<int>*/(0);
69-
var extendsNumReturnArg2 = extendsNumReturnArg/*<String>*/("");
69+
var extendsNumReturnArg2 = extendsNumReturnArg/*<num>*/("");
7070
num extendsNumReturnArg3 = extendsNumReturnArg/*<num>*/(0);
7171
int extendsNumReturnArg4 = extendsNumReturnArg/*<int>*/(0);
7272
int extendsNumReturnArg5 = extendsNumReturnArg/*<int>*/(0.5);

pkg/analyzer/lib/src/dart/analysis/experiments.g.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ class ExperimentalFeatures {
348348
documentation:
349349
'Use type parameter bounds more extensively in type inference.',
350350
experimentalReleaseVersion: null,
351-
releaseVersion: null,
351+
releaseVersion: Version.parse('3.7.0'),
352352
);
353353

354354
static final inline_class = ExperimentalFeature(
@@ -606,7 +606,7 @@ class IsEnabledByDefault {
606606
static const bool inference_update_4 = false;
607607

608608
/// Default state of the experiment "inference-using-bounds"
609-
static const bool inference_using_bounds = false;
609+
static const bool inference_using_bounds = true;
610610

611611
/// Default state of the experiment "inline-class"
612612
static const bool inline_class = true;

pkg/analyzer/lib/src/dart/element/least_greatest_closure.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ class LeastGreatestClosureHelper extends ReplacementVisitor {
7171
// - The least closure of `S` with respect to `L` is `Never`
7272
// - The greatest closure of `S` with respect to `L` is `Function`
7373
for (var typeParameter in node.typeFormals) {
74-
var bound = typeParameter.bound as TypeImpl;
75-
if (bound.referencesAny(eliminationTargets)) {
74+
if (typeParameter.bound case TypeImpl bound?
75+
when bound.referencesAny(eliminationTargets)) {
7676
return _functionReplacement;
7777
}
7878
}

pkg/analyzer/test/generated/strong_mode_test.dart

Lines changed: 16 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1091,11 +1091,10 @@ class StrongModeLocalInferenceTest extends PubPackageResolutionTest {
10911091
// Test that upwards inference fails when the solution doesn't
10921092
// match the bound.
10931093
MethodInvocation invoke = await _testFutureOr(r'''
1094-
Future<T> mk<T extends Future<Object>>(FutureOr<T> x) => null;
1094+
T mk<T extends Future<Object>>(FutureOr<T> x) => null;
10951095
dynamic test() => mk(new Future<int>.value(42));
10961096
''', expectedErrors: [
1097-
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 83, 4),
1098-
error(CompileTimeErrorCode.COULD_NOT_INFER, 111, 2),
1097+
error(CompileTimeErrorCode.RETURN_OF_INVALID_TYPE_FROM_FUNCTION, 75, 4),
10991098
]);
11001099
_isFutureOfInt(invoke.staticType as InterfaceType);
11011100
}
@@ -1324,21 +1323,8 @@ test() {
13241323
''';
13251324
await assertErrorsInCode(code, [
13261325
error(WarningCode.UNUSED_LOCAL_VARIABLE, 94, 5),
1327-
error(CompileTimeErrorCode.COULD_NOT_INFER, 102, 1),
1326+
error(CompileTimeErrorCode.INVALID_ASSIGNMENT, 102, 3),
13281327
]);
1329-
1330-
_expectInferenceError(r'''
1331-
Couldn't infer type parameter 'T'.
1332-
1333-
Tried to infer 'String' for 'T' which doesn't work:
1334-
Type parameter 'T' is declared to extend 'num' producing 'num'.
1335-
The type 'String' was inferred from:
1336-
Return type declared as 'T Function(T)'
1337-
used where 'String Function(String)' is required.
1338-
1339-
Consider passing explicit type argument(s) to the generic.
1340-
1341-
''');
13421328
}
13431329

13441330
test_inference_error_genericFunction() async {
@@ -1355,18 +1341,7 @@ test(Iterable values) {
13551341
await assertErrorsInCode(code, [
13561342
error(WarningCode.UNUSED_LOCAL_VARIABLE, 158, 1),
13571343
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 195, 3),
1358-
error(CompileTimeErrorCode.COULD_NOT_INFER, 195, 3),
13591344
]);
1360-
_expectInferenceError(r'''
1361-
Couldn't infer type parameter 'T'.
1362-
1363-
Tried to infer 'dynamic' for 'T' which doesn't work:
1364-
Function type declared as 'T Function<T extends num>(T, T)'
1365-
used where 'num Function(num, dynamic)' is required.
1366-
1367-
Consider passing explicit type argument(s) to the generic.
1368-
1369-
''');
13701345
}
13711346

13721347
test_inference_error_returnContext() async {
@@ -2021,7 +1996,6 @@ abstract class Iterable<T> {
20211996
num test(Iterable values) => values.fold(values.first as num, max);
20221997
''';
20231998
await assertErrorsInCode(code, [
2024-
error(CompileTimeErrorCode.COULD_NOT_INFER, 190, 3),
20251999
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 190, 3),
20262000
]);
20272001

@@ -2083,9 +2057,9 @@ MethodInvocation
20832057
parameter: ParameterMember
20842058
base: root::@parameter::f
20852059
substitution: {S: num}
2086-
staticType: dynamic Function(dynamic, dynamic)
2060+
staticType: num Function(num, num)
20872061
typeArgumentTypes
2088-
dynamic
2062+
num
20892063
rightParenthesis: )
20902064
staticInvokeType: num Function(num, num Function(num, dynamic))
20912065
staticType: num
@@ -4832,8 +4806,8 @@ class C<T> {
48324806
}
48334807
}
48344808
''', [
4835-
error(CompileTimeErrorCode.COULD_NOT_INFER, 95, 1),
4836-
error(CompileTimeErrorCode.COULD_NOT_INFER, 95, 1),
4809+
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 97, 4),
4810+
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 103, 4),
48374811
]);
48384812

48394813
var node = findNode.singleMethodInvocation;
@@ -4851,20 +4825,20 @@ MethodInvocation
48514825
literal: null
48524826
parameter: ParameterMember
48534827
base: <testLibraryFragment>::@class::C::@method::m::@parameter::p0
4854-
substitution: {S0: Null, S1: Null}
4828+
substitution: {S0: T, S1: List<T>}
48554829
staticType: Null
48564830
NullLiteral
48574831
literal: null
48584832
parameter: ParameterMember
48594833
base: <testLibraryFragment>::@class::C::@method::m::@parameter::p1
4860-
substitution: {S0: Null, S1: Null}
4834+
substitution: {S0: T, S1: List<T>}
48614835
staticType: Null
48624836
rightParenthesis: )
4863-
staticInvokeType: void Function(Null, Null)
4837+
staticInvokeType: void Function(T, List<T>)
48644838
staticType: void
48654839
typeArgumentTypes
4866-
Null
4867-
Null
4840+
T
4841+
List<T>
48684842
''');
48694843
}
48704844

@@ -4910,7 +4884,7 @@ class C<T> {
49104884
}
49114885
}
49124886
''', [
4913-
error(CompileTimeErrorCode.COULD_NOT_INFER, 65, 1),
4887+
error(CompileTimeErrorCode.ARGUMENT_TYPE_NOT_ASSIGNABLE, 67, 4),
49144888
]);
49154889

49164890
var node = findNode.singleMethodInvocation;
@@ -4928,13 +4902,13 @@ MethodInvocation
49284902
literal: null
49294903
parameter: ParameterMember
49304904
base: <testLibraryFragment>::@class::C::@method::m::@parameter::p0
4931-
substitution: {S: Null}
4905+
substitution: {S: T}
49324906
staticType: Null
49334907
rightParenthesis: )
4934-
staticInvokeType: void Function(Null)
4908+
staticInvokeType: void Function(T)
49354909
staticType: void
49364910
typeArgumentTypes
4937-
Null
4911+
T
49384912
''');
49394913
}
49404914

pkg/analyzer/test/src/dart/analysis/analysis_context_collection_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -413,6 +413,7 @@ analysisOptions
413413
inference-update-1
414414
inference-update-2
415415
inference-update-3
416+
inference-using-bounds
416417
inline-class
417418
named-arguments-anywhere
418419
non-nullable
@@ -489,6 +490,7 @@ analysisOptions
489490
inference-update-1
490491
inference-update-2
491492
inference-update-3
493+
inference-using-bounds
492494
inline-class
493495
named-arguments-anywhere
494496
non-nullable

pkg/analyzer/test/src/dart/resolution/augmented_invocation_test.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,15 +282,13 @@ part 'test.dart';
282282
T foo<T extends num>(T a) => throw 0;
283283
''');
284284

285-
await assertErrorsInCode('''
285+
await assertNoErrorsInCode('''
286286
part of 'a.dart';
287287
288288
augment void foo<T2 extends num>(T2 a) {
289289
augmented('');
290290
}
291-
''', [
292-
error(CompileTimeErrorCode.COULD_NOT_INFER, 62, 9),
293-
]);
291+
''');
294292

295293
var node = findNode.singleAugmentedInvocation;
296294
assertResolvedNodeText(node, r'''
@@ -304,7 +302,7 @@ AugmentedInvocation
304302
rightParenthesis: )
305303
element: package:test/a.dart::<fragment>::@function::foo
306304
element2: package:test/a.dart::@function::foo
307-
staticType: String
305+
staticType: num
308306
''');
309307
}
310308

pkg/analyzer/test/src/dart/resolution/type_inference/extension_methods_test.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -701,11 +701,12 @@ f(String s) {
701701
E(s).foo();
702702
}
703703
''', [
704-
error(CompileTimeErrorCode.COULD_NOT_INFER, 69, 1),
704+
error(CompileTimeErrorCode.EXTENSION_OVERRIDE_ARGUMENT_NOT_ASSIGNABLE, 71,
705+
1),
705706
]);
706707
var override = findNode.extensionOverride('E(s)');
707-
assertElementTypes(override.typeArgumentTypes, ['String']);
708-
assertType(override.extendedType, 'String');
708+
assertElementTypes(override.typeArgumentTypes, ['num']);
709+
assertType(override.extendedType, 'num');
709710
}
710711

711712
test_override_inferTypeArguments_getter() async {

0 commit comments

Comments
 (0)