top_level_cycle
The type of '{0}' can't be inferred because it depends on itself through the cycle: {1}.
Description
#The analyzer produces this diagnostic when a top-level variable has no type annotation and the variable's initializer refers to the variable, either directly or indirectly.
Example
#The following code produces this diagnostic because the variables x
and
y
are defined in terms of each other, and neither has an explicit type,
so the type of the other can't be inferred:
var x = y;
var y = x;
Common fixes
#If the two variables don't need to refer to each other, then break the cycle:
var x = 0;
var y = x;
If the two variables need to refer to each other, then give at least one of them an explicit type:
int x = y;
var y = x;
除非另有说明,文档之所提及适用于 Dart 3.7.3 版本,本页面最后更新时间: 2025-05-08。 查看文档源码 或者 报告页面问题。