Skip to content

Parameterized type hierarchy change #2714

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 3 additions & 8 deletions lib/src/element_type.dart
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,6 @@ mixin Aliased implements ElementType {
_aliasArguments ??= type.aliasArguments
.map((f) => ElementType.from(f, library, packageGraph))
.toList(growable: false);

Iterable<ElementType> _typeArguments;
@override
Iterable<ElementType> get typeArguments =>
_typeArguments ??= (type as ParameterizedType)
.typeArguments
.map((f) => ElementType.from(f, library, packageGraph))
.toList(growable: false);
}

class AliasedElementType extends ParameterizedElementType with Aliased {
Expand All @@ -251,6 +243,9 @@ class AliasedElementType extends ParameterizedElementType with Aliased {
assert(type.aliasElement != null);
}

@override
ParameterizedType get type;

/// Parameters, if available, for the underlying typedef.
List<Parameter> get aliasedParameters =>
modelElement.isCallable ? modelElement.parameters : [];
Expand Down
18 changes: 16 additions & 2 deletions test/end2end/model_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4068,6 +4068,7 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
TopLevelVariable nodocGetter, nodocSetter;
TopLevelVariable complicatedReturn;
TopLevelVariable meaningOfLife, importantComputations;
TopLevelVariable genericTypedefCombo;

setUpAll(() {
v = exLibrary.properties.firstWhere((p) => p.name == 'number');
Expand All @@ -4090,6 +4091,19 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
fakeLibrary.properties.firstWhere((p) => p.name == 'setAndGet');
mapWithDynamicKeys = fakeLibrary.properties
.firstWhere((p) => p.name == 'mapWithDynamicKeys');
genericTypedefCombo = fakeLibrary.properties
.firstWhere((p) => p.name == 'genericTypedefCombo');
});

test(
'Verify that combos with a generic typedef modelType can render correctly',
() {
// TODO(jcollins-g): After analyzer 2.0.0, this can be `isEmpty`.
expect(genericTypedefCombo.modelType.typeArguments, isNotNull);
expect(
genericTypedefCombo.modelType.linkedName,
equals(
'<a href=\"%%__HTMLBASE_dartdoc_internal__%%fake/NewGenericTypedef.html\">NewGenericTypedef</a>'));
});

test('Verify that final and late show up (or not) appropriately', () {
Expand Down Expand Up @@ -4554,9 +4568,9 @@ String topLevelFunction(int param1, bool param2, Cool coolBeans,
expect(
oldgeneric.modelType.linkedName,
isIn([
'T Function<span class="signature">(<span class="parameter" id="GenericTypedef-param-input"><span class="type-annotation">T</span> <span class="parameter-name">input</span></span>)</span>',
// Remove following after analyzer 2.0.0
'T Function<span class="signature">(<span class="parameter" id="param-input"><span class="type-annotation">T</span> <span class="parameter-name">input</span></span>)</span>',
// Remove below option after analyzer 1.6.0.
'Function(<span class=\"parameter\" id=\"GenericTypedef-param-input\"><span class=\"type-annotation\">T</span></span>) → T'
]));
expect(
generic.modelType.linkedName,
Expand Down
3 changes: 3 additions & 0 deletions testing/test_package/lib/fake.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,9 @@ typedef T GenericTypedef<T>(T input);
/// A typedef with the new style generic function syntax.
typedef NewGenericTypedef<T> = List<S> Function<S>(T, int, bool);

/// A top level variable with a generic typedef type.
NewGenericTypedef genericTypedefCombo;

/// A complicated type parameter to ATypeTakingClass.
ATypeTakingClass<String Function(int)> get complicatedReturn => null;

Expand Down