Skip to content

Commit e9df1ee

Browse files
[nnbd_migration] Add an edge origin for inferred parameter substitution
Change-Id: I37ce933e05a6b7ad7b8fdcc26f44968ae92516be Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137658 Reviewed-by: Paul Berry <[email protected]>
1 parent 42d0c82 commit e9df1ee

File tree

5 files changed

+41
-1
lines changed

5 files changed

+41
-1
lines changed

pkg/analysis_server/lib/src/edit/nnbd_migration/info_builder.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ class InfoBuilder {
182182
if (origin.kind == EdgeOriginKind.typeParameterInstantiation) {
183183
return 'This type parameter is instantiated with a nullable type';
184184
}
185+
if (origin.kind == EdgeOriginKind.inferredTypeParameterInstantiation) {
186+
return 'This type parameter is instantiated with an inferred nullable '
187+
'type';
188+
}
185189

186190
CompilationUnit unit = node.thisOrAncestorOfType<CompilationUnit>();
187191
int lineNumber = unit.lineInfo.getLocation(node.offset).lineNumber;

pkg/analysis_server/test/src/edit/nnbd_migration/info_builder_test.dart

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -342,6 +342,27 @@ void main() {
342342
details: ['This type parameter is instantiated with a nullable type']);
343343
}
344344

345+
Future<void> test_bound_method_implicit() async {
346+
UnitInfo unit = await buildInfoForSingleTestFile('''
347+
f<T extends Object>(T/*!*/ t) {}
348+
349+
void main() {
350+
f(null);
351+
}
352+
''', migratedContent: '''
353+
f<T extends Object?>(T/*!*/ t) {}
354+
355+
void main() {
356+
f(null);
357+
}
358+
''');
359+
List<RegionInfo> regions = unit.regions;
360+
expect(regions, hasLength(2));
361+
assertRegion(region: regions[0], offset: 18, details: [
362+
'This type parameter is instantiated with an inferred nullable type'
363+
]);
364+
}
365+
345366
Future<void> test_discardCondition() async {
346367
UnitInfo unit = await buildInfoForSingleTestFile('''
347368
void g(int i) {

pkg/nnbd_migration/lib/instrumentation.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ enum EdgeOriginKind {
137137
ifNull,
138138
implicitMixinSuperCall,
139139
implicitNullInitializer,
140+
inferredTypeParameterInstantiation,
140141
initializerInference,
141142
instanceCreation,
142143
instantiateToBounds,

pkg/nnbd_migration/lib/src/edge_builder.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2304,7 +2304,11 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
23042304
offset: node.offset))
23052305
.toList();
23062306
instrumentation?.implicitTypeArguments(source, node, argumentTypes);
2307-
calleeType = _handleInstantiation(calleeType, argumentTypes, null);
2307+
calleeType = _handleInstantiation(
2308+
calleeType,
2309+
argumentTypes,
2310+
List.filled(argumentTypes.length,
2311+
InferredTypeParameterInstantiationOrigin(source, node)));
23082312
} else if (constructorTypeParameters != null) {
23092313
// No need to instantiate; caller has already substituted in the
23102314
// correct type arguments.

pkg/nnbd_migration/lib/src/edge_origin.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,16 @@ class TypeParameterInstantiationOrigin extends EdgeOrigin {
434434
TypeAnnotation get node => super.node as TypeAnnotation;
435435
}
436436

437+
/// Edge origin resulting from the inference of a type parameter, which
438+
/// can affects the nullability of that type parameter's bound.
439+
class InferredTypeParameterInstantiationOrigin extends EdgeOrigin {
440+
InferredTypeParameterInstantiationOrigin(Source source, AstNode node)
441+
: super(source, node);
442+
443+
@override
444+
EdgeOriginKind get kind => EdgeOriginKind.inferredTypeParameterInstantiation;
445+
}
446+
437447
/// Edge origin resulting from the read of a variable that has not been
438448
/// definitely assigned a value.
439449
class UninitializedReadOrigin extends EdgeOrigin {

0 commit comments

Comments
 (0)