Can AstNode.root return anything other than a CompilationUnit?

37 views
Skip to first unread message

dark...@gmail.com

unread,
Dec 2, 2023, 7:13:57 AM12/2/23
to Dart Analyzer Discussion
Hello!

I was using AstNode.root earlier to search for the CompilationUnit of a given node.
Yet I wouldn't help but wonder: Since AstNode.root is typed as AstNode, not CompilationUnit, when could it return something other than a CompilationUnit?

Thanks!

Brian Wilkerson

unread,
Dec 2, 2023, 11:08:08 AM12/2/23
to analyzer...@dartlang.org
When we serialize the element model (our summary files) we need to capture the constant expressions used in `const` constructors (so that we can evaluate them as part of constant evaluation). When we deserialize those expressions they are not attached to a full AST structure, so the `root` of any node in that structure will be the top-most node in the representation of the expression. Unless you're accessing those expressions (which are not available through the public API), the `root` should always be a `CompilationUnit`.

--
You received this message because you are subscribed to the Google Groups "Dart Analyzer Discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to analyzer-discu...@dartlang.org.
To view this discussion on the web visit https://groups.google.com/a/dartlang.org/d/msgid/analyzer-discuss/3c90b70f-0326-4efa-a27f-b99a920e1c4dn%40dartlang.org.
Reply all
Reply to author
Forward
0 new messages