From 8d8a1a02c25736edee488122ea35d7626b0006e2 Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Wed, 12 Jun 2024 14:53:28 -0700 Subject: [PATCH 1/2] Fix referencing an aliased type parameter. (#3784) What is an aliased type parameter? Good question! `typedef TD = T;` is such an alias. The fix is pretty simple, we just weren't previously handling this case, or being safe. --- lib/src/element_type.dart | 32 ++++++++++++++++++++------------ test/typedef_test.dart | 15 +++++++++++++++ 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/lib/src/element_type.dart b/lib/src/element_type.dart index 983579b218..aa7e1d0f2a 100644 --- a/lib/src/element_type.dart +++ b/lib/src/element_type.dart @@ -272,20 +272,28 @@ abstract class DefinedElementType extends ElementType { factory DefinedElementType._from(DartType type, ModelElement modelElement, Library library, PackageGraph packageGraph) { - // `TypeAliasElement.alias.element` has different implications. - // In that case it is an actual type alias of some kind (generic or - // otherwise). Here however `alias.element` signals that this is a type - // referring to an alias. if (type is! TypeAliasElement && type.alias != null) { - return AliasedElementType._( - type as ParameterizedType, library, packageGraph, modelElement); + // Here, `alias.element` signals that this is a type referring to an + // alias. (`TypeAliasElement.alias.element` has different implications. + // In that case it is an actual type alias of some kind (generic or + // otherwise).) + return switch (type) { + TypeParameterType() => + TypeParameterElementType._(type, library, packageGraph, modelElement), + ParameterizedType() => + AliasedElementType._(type, library, packageGraph, modelElement), + _ => throw UnimplementedError( + 'No ElementType implemented for aliased ${type.runtimeType}'), + }; } - if (type is TypeParameterType) { - return TypeParameterElementType._( - type, library, packageGraph, modelElement); - } - return ParameterizedElementType._( - type as ParameterizedType, library, packageGraph, modelElement); + return switch (type) { + TypeParameterType() => + TypeParameterElementType._(type, library, packageGraph, modelElement), + ParameterizedType() => + ParameterizedElementType._(type, library, packageGraph, modelElement), + _ => throw UnimplementedError( + 'No ElementType implemented for ${type.runtimeType}'), + }; } @override diff --git a/test/typedef_test.dart b/test/typedef_test.dart index ae035d6c1d..2e26170a50 100644 --- a/test/typedef_test.dart +++ b/test/typedef_test.dart @@ -40,6 +40,21 @@ typedef T = C; expect(tTypedef.aliasedType, isA()); } + void test_extensionType_generic_referenceToTypeParameter() async { + var library = await bootPackageWithLibrary(''' +typedef TD = T; + +/// Text [T]. +extension type ET(TD _) {} +'''); + + expect( + library.extensionTypes.named('ET').documentationAsHtml, + // There is no way to link to a type parameter. + contains('

Text T.

'), + ); + } + void test_extensionType_basic() async { var library = await bootPackageWithLibrary(''' extension type E(int i) {} From b6acf3b7c904affd8e87cfa54aa4cf726011d41b Mon Sep 17 00:00:00 2001 From: Sam Rawlins Date: Thu, 27 Jun 2024 08:12:43 -0700 Subject: [PATCH 2/2] Bump to 8.0.9+1 --- CHANGELOG.md | 4 ++++ dartdoc_options.yaml | 2 +- lib/src/version.dart | 2 +- pubspec.yaml | 2 +- 4 files changed, 7 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a1a9c8650..5d7a6b2449 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 8.0.9+1 + +* Fix referencing an aliased type parameter. (#3784) + ## 8.0.9 * Deprecate the `missingCodeBlockLanguage` warning. This is replaced with the diff --git a/dartdoc_options.yaml b/dartdoc_options.yaml index 0e9fb7968c..27772d8af6 100644 --- a/dartdoc_options.yaml +++ b/dartdoc_options.yaml @@ -1,4 +1,4 @@ dartdoc: linkToSource: root: '.' - uriTemplate: 'https://github.com/dart-lang/dartdoc/blob/v8.0.9/%f%#L%l%' + uriTemplate: 'https://github.com/dart-lang/dartdoc/blob/v8.0.9+1/%f%#L%l%' diff --git a/lib/src/version.dart b/lib/src/version.dart index 57ce5ec075..3efc8b103a 100644 --- a/lib/src/version.dart +++ b/lib/src/version.dart @@ -1 +1 @@ -const packageVersion = '8.0.9'; +const packageVersion = '8.0.9+1'; diff --git a/pubspec.yaml b/pubspec.yaml index 16dc577ca3..8501cedf4d 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,5 +1,5 @@ name: dartdoc -version: 8.0.9 +version: 8.0.9+1 description: A non-interactive HTML documentation generator for Dart source code. repository: https://github.com/dart-lang/dartdoc