isTopTypeName function
True for the names that denote a TOP TYPE — one every value inhabits.
dynamic, Object, Object? and void. Treating them as "matches
anything" keeps a comparison permissive exactly where Dart's own
assignability is permissive, which matters most on annotations the
interpreter can only resolve coarsely.
One predicate, because three used to disagree. SCD90 measured the
question X <: <top> across the implementations of RuntimeType and found
NamedRuntimeType and TypeParameter answering true for all of
Object / dynamic / void, while BridgedClass answered true only for
a BridgedClass named Object — false for dynamic, for void, and for
every NamedRuntimeType target including Object, which is the sentinel
this very file documents as how dynamic is spelled when a richer type
object is unavailable. Five of six cells wrong in one implementation, right
in the others. So the fix is one shared answer rather than a fourth private
copy of it.
Object? is included although nothing was measured spelling it: a type
whose name is literally Object? can only be the nullable top type, so
admitting it cannot be wrong, and omitting it would be the next asymmetry.
Implementation
bool isTopTypeName(String n) =>
n == 'dynamic' || n == 'Object' || n == 'Object?' || n == 'void';