Backends often use expr.getStaticType() to get the static type of an expression.
The ConstantExpression implements this by just returning ConstantExpression.type which is often Dynamic as that's the default value. Though instead of this it could rather make it more precise via
@@ -4650,7 +4650,10 @@ class ConstantExpression extends Expression {
getStaticTypeInternal(context);
@override
- DartType getStaticTypeInternal(StaticTypeContext context) => type;
+ DartType getStaticTypeInternal(StaticTypeContext context) => constant.getType(context);
@override
R accept<R>(ExpressionVisitor<R> v) => v.visitConstantExpression(this);
This would avoid backends having to workaround this issue and special casing ConstantExpression specially.