Open
Description
Write this in dartpad.dev:
class A{
const A(this.d) : assert(d >= Duration.zero);
final Duration d;
}
void main () {
const a = A(Duration(days: 1));
}
You'll get this error only on line 8:
In constant expressions, operands of this operator must be of type 'num'.
I tested it on my local development machine and still got the same error.
My question is, why can't this error be shown in line 2? I do believe this should appear there since packages that do not have tests would never see this and since this example only requires a single Duration
as a parameter (I have a package that could have a future case like this), this class should not be able to be constant.
Second question, why can't this be asserted in constant expressions even if Duration
s are constant classes? Can't this be converted to Duration.inMicroseconds
to assert internally?