diff --git a/lib/src/model/extension.dart b/lib/src/model/extension.dart index 83834ad6dc..34c68fe6e7 100644 --- a/lib/src/model/extension.dart +++ b/lib/src/model/extension.dart @@ -45,6 +45,7 @@ class Extension extends Container { if (extendedType is DynamicType || extendedType is VoidType) { return true; } + extendedType = library.element.typeSystem.promoteToNonNull(extendedType); var otherType = container.modelType.type; if (otherType is InterfaceType) { otherType = library.element.typeSystem.instantiateInterfaceToBounds( diff --git a/test/templates/class_test.dart b/test/templates/class_test.dart index f1644dff5b..2e46a46a88 100644 --- a/test/templates/class_test.dart +++ b/test/templates/class_test.dart @@ -314,6 +314,25 @@ extension E on C { ]); } + void test_instancePropertyAccessor_fromExtension_onNullableType() async { + await createPackageWithLibrary(''' +class C {} + +extension E on C? { + /// An instance getter. + int get f => 1; +} +'''); + var htmlLines = readLines(['lib', 'C-class.html']); + + htmlLines.expectMainContentContainsAllInOrder([ + matches('

Properties

'), + matches('
'), + matches('f'), + matches('An instance getter.'), + ]); + } + void test_instancePropertyAccessor_fromExtensionOfSupertype() async { await createPackageWithLibrary(''' class C {}