File tree Expand file tree Collapse file tree 5 files changed +41
-1
lines changed
lib/src/edit/nnbd_migration
test/src/edit/nnbd_migration Expand file tree Collapse file tree 5 files changed +41
-1
lines changed Original file line number Diff line number Diff 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;
Original file line number Diff line number Diff 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 ('''
347368void g(int i) {
Original file line number Diff line number Diff line change @@ -137,6 +137,7 @@ enum EdgeOriginKind {
137137 ifNull,
138138 implicitMixinSuperCall,
139139 implicitNullInitializer,
140+ inferredTypeParameterInstantiation,
140141 initializerInference,
141142 instanceCreation,
142143 instantiateToBounds,
Original file line number Diff line number Diff 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.
Original file line number Diff line number Diff 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.
439449class UninitializedReadOrigin extends EdgeOrigin {
You can’t perform that action at this time.
0 commit comments