Skip to main content

recursive_compile_time_constant

The compile-time constant expression depends on itself.

Description

#

The analyzer produces this diagnostic when the value of a compile-time constant is defined in terms of itself, either directly or indirectly, creating an infinite loop.

Example

#

The following code produces this diagnostic twice because both of the constants are defined in terms of the other:

dart
const secondsPerHour = minutesPerHour * 60;
const minutesPerHour = secondsPerHour / 60;

Common fixes

#

Break the cycle by finding an alternative way of defining at least one of the constants:

dart
const secondsPerHour = minutesPerHour * 60;
const minutesPerHour = 60;