Skip to content

Commit 42d0c82

Browse files
[nnbd_migration] Add edge origin for explicit instantiation params
Change-Id: I9feebb693d8e97027019b5ff2e936ce0fd69bd3c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/137655 Reviewed-by: Paul Berry <[email protected]>
1 parent 1881441 commit 42d0c82

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

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

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,28 @@ C<int?/*?*/>? c;
298298
details: ['This type parameter is instantiated with a nullable type']);
299299
}
300300

301+
Future<void> test_bound_instantiation_explicit() async {
302+
UnitInfo unit = await buildInfoForSingleTestFile('''
303+
class C<T extends Object> {}
304+
305+
void main() {
306+
C<int/*?*/>();
307+
}
308+
''', migratedContent: '''
309+
class C<T extends Object?> {}
310+
311+
void main() {
312+
C<int?/*?*/>();
313+
}
314+
''');
315+
List<RegionInfo> regions = unit.regions;
316+
expect(regions, hasLength(2));
317+
assertRegion(
318+
region: regions[0],
319+
offset: 24,
320+
details: ['This type parameter is instantiated with a nullable type']);
321+
}
322+
301323
Future<void> test_bound_method_explicit() async {
302324
UnitInfo unit = await buildInfoForSingleTestFile('''
303325
f<T extends Object> {}

pkg/nnbd_migration/lib/src/edge_builder.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -889,12 +889,16 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
889889
Iterable<DartType> typeArgumentTypes;
890890
List<DecoratedType> decoratedTypeArguments;
891891
var typeArguments = node.constructorName.type.typeArguments;
892+
List<EdgeOrigin> parameterEdgeOrigins;
892893
if (typeArguments != null) {
893894
typeArguments.accept(this);
894895
typeArgumentTypes = typeArguments.arguments.map((t) => t.type);
895896
decoratedTypeArguments = typeArguments.arguments
896897
.map((t) => _variables.decoratedTypeAnnotation(source, t))
897898
.toList();
899+
parameterEdgeOrigins = typeArguments.arguments
900+
.map((typeAnn) => TypeParameterInstantiationOrigin(source, typeAnn))
901+
.toList();
898902
} else {
899903
var staticType = node.staticType;
900904
if (staticType is InterfaceType) {
@@ -926,7 +930,7 @@ class EdgeBuilder extends GeneralizingAstVisitor<DecoratedType>
926930
typeArguments: decoratedTypeArguments);
927931
var calleeType = getOrComputeElementType(callee, targetType: createdType);
928932
for (var i = 0; i < decoratedTypeArguments.length; ++i) {
929-
_checkAssignment(null,
933+
_checkAssignment(parameterEdgeOrigins?.elementAt(i),
930934
source: decoratedTypeArguments[i],
931935
destination:
932936
_variables.decoratedTypeParameterBound(typeParameters[i]),

0 commit comments

Comments
 (0)