Skip to content

Commit 4b2b07b

Browse files
johnniwintherCommit Queue
authored andcommitted
[_fe_analyzer_shared] Test late resolution of macro metadata
This delays the resolution of the identifier in metadata, such the parsed annotation expression is initially unresolved and `Expression.resolve` must be called in order to resolve it. This execises the support for references to identifiers declare via macros, which will initially occur as unresolved identifiers. Change-Id: I4863ce950ded0b9d2c1744421d9751cddea6e80c Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391641 Reviewed-by: Konstantin Shcheglov <[email protected]> Reviewed-by: Jens Johansen <[email protected]>
1 parent c0381d0 commit 4b2b07b

File tree

28 files changed

+2851
-502
lines changed

28 files changed

+2851
-502
lines changed

pkg/_fe_analyzer_shared/lib/src/testing/metadata_helper.dart

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,32 @@ Expression unwrap(Expression expression) {
2323
return expression;
2424
}
2525

26+
/// Creates a list containing structured and readable textual representation of
27+
/// the [unresolved] and [resolved] expressions.
28+
List<String> expressionsToText(
29+
{required Expression unresolved, required Expression resolved}) {
30+
List<String> list = [];
31+
list.add('unresolved=${expressionToText(unwrap(unresolved))}');
32+
33+
// The identifiers in [expression] haven't been resolved, so
34+
// we call [Expression.resolve] to convert the expression into
35+
// its resolved equivalent.
36+
Expression lateResolved = unresolved.resolve() ?? unresolved;
37+
38+
String earlyResolvedText = expressionToText(unwrap(resolved));
39+
String lateResolvedText = expressionToText(unwrap(lateResolved));
40+
41+
// These should always be the same. If not we include both to
42+
// signal the error.
43+
if (earlyResolvedText == lateResolvedText) {
44+
list.add('resolved=${earlyResolvedText}');
45+
} else {
46+
list.add('early-resolved=${earlyResolvedText}');
47+
list.add('late-resolved=${lateResolvedText}');
48+
}
49+
return list;
50+
}
51+
2652
/// Creates a structured and readable textual representation of [expression].
2753
String expressionToText(Expression expression) {
2854
Writer writer = new Writer();
@@ -308,10 +334,11 @@ class Writer {
308334
case DynamicTypeAnnotation():
309335
_write('dynamic');
310336
case InvalidTypeAnnotation():
311-
_write('<<invalid-type-annotation>>');
337+
_write('{invalid-type-annotation}');
312338
case UnresolvedTypeAnnotation():
313-
_write('<<unresolved-type-annotation:');
339+
_write('{unresolved-type-annotation:');
314340
_unresolvedToText(typeAnnotation.unresolved);
341+
_write('}');
315342
case FunctionTypeAnnotation(:TypeAnnotation? returnType):
316343
if (returnType != null) {
317344
_typeAnnotationToText(returnType);

0 commit comments

Comments
 (0)