Skip to content
This repository was archived by the owner on Feb 4, 2025. It is now read-only.

Commit 1e13d2f

Browse files
authored
fix converting type annotations (#157)
1 parent 4c4adc1 commit 1e13d2f

File tree

2 files changed

+28
-1
lines changed

2 files changed

+28
-1
lines changed

pkgs/_analyzer_cfe_macros/lib/metadata_converter.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,10 @@ T? convert<T>(Object? object) => switch (object) {
502502
front_end.TypedefReference o =>
503503
dart_model.TypedefReference(name: convert(o.name)) as T,
504504
front_end.TypeLiteral o =>
505-
dart_model.TypeLiteral(typeAnnotation: convert(o.typeAnnotation)) as T,
505+
dart_model.TypeLiteral(
506+
typeAnnotation: convertToTypeAnnotation(o.typeAnnotation),
507+
)
508+
as T,
506509
front_end.TypeReference o => dart_model.TypeReference() as T,
507510
front_end.UnaryExpression o =>
508511
dart_model.UnaryExpression(

pkgs/_analyzer_cfe_macros/test/metadata_converter_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,4 +81,28 @@ void main() {
8181
});
8282
});
8383
});
84+
85+
test('converts a type literal', () {
86+
final invocation = TypeLiteral(NamedTypeAnnotation(TestClassReference()));
87+
88+
Scope.query.run(() {
89+
expect(convert<Object>(invocation), <String, Object?>{
90+
'typeAnnotation': {
91+
'type': 'NamedTypeAnnotation',
92+
'value': {
93+
'reference': {
94+
'type': 'ClassReference',
95+
'value': {'name': 'Test'},
96+
},
97+
'typeArguments': <Object>[],
98+
},
99+
},
100+
});
101+
});
102+
});
103+
}
104+
105+
class TestClassReference implements ClassReference {
106+
@override
107+
String get name => 'Test';
84108
}

0 commit comments

Comments
 (0)