@@ -985,8 +985,8 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
985
985
}
986
986
987
987
@override
988
- Constant ? visitNamedExpression (NamedExpression node) =>
989
- node.expression. accept ( this );
988
+ Constant visitNamedExpression (NamedExpression node) =>
989
+ _getConstant ( node.expression);
990
990
991
991
@override
992
992
Constant ? visitNamedType (NamedType node) {
@@ -1037,8 +1037,8 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
1037
1037
}
1038
1038
1039
1039
@override
1040
- Constant ? visitParenthesizedExpression (ParenthesizedExpression node) =>
1041
- node.expression. accept ( this );
1040
+ Constant visitParenthesizedExpression (ParenthesizedExpression node) =>
1041
+ _getConstant ( node.expression);
1042
1042
1043
1043
@override
1044
1044
Constant ? visitPrefixedIdentifier (PrefixedIdentifier node) {
@@ -1078,13 +1078,10 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
1078
1078
}
1079
1079
1080
1080
@override
1081
- Constant ? visitPrefixExpression (PrefixExpression node) {
1082
- // TODO(kallentu): Remove unwrapping of Constant.
1083
- var operandConstant = node.operand.accept (this );
1084
- var operand = operandConstant is DartObjectImpl ? operandConstant : null ;
1085
- if (operand != null && operand.isNull) {
1086
- _error (node, CompileTimeErrorCode .CONST_EVAL_THROWS_EXCEPTION );
1087
- return null ;
1081
+ Constant visitPrefixExpression (PrefixExpression node) {
1082
+ var operand = _getConstant (node.operand);
1083
+ if (operand is ! DartObjectImpl ) {
1084
+ return operand;
1088
1085
}
1089
1086
if (node.staticElement? .enclosingElement is ExtensionElement ) {
1090
1087
// TODO(kallentu): Don't report error here.
@@ -1103,7 +1100,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
1103
1100
// TODO(https://github.com/dart-lang/sdk/issues/47061): Use a specific
1104
1101
// error code.
1105
1102
_error (node, null );
1106
- return null ;
1103
+ return InvalidConstant (node, CompileTimeErrorCode . INVALID_CONSTANT ) ;
1107
1104
}
1108
1105
}
1109
1106
@@ -1800,15 +1797,14 @@ class DartObjectComputer {
1800
1797
}
1801
1798
}
1802
1799
1803
- DartObjectImpl ? bitNot (Expression node, DartObjectImpl ? evaluationResult) {
1804
- if (evaluationResult != null ) {
1805
- try {
1806
- return evaluationResult. bitNot (_typeSystem);
1807
- } on EvaluationException catch (exception) {
1808
- _errorReporter.reportErrorForNode (exception.errorCode, node);
1809
- }
1800
+ Constant bitNot (Expression node, DartObjectImpl evaluationResult) {
1801
+ try {
1802
+ return evaluationResult. bitNot (_typeSystem);
1803
+ } on EvaluationException catch (exception) {
1804
+ // TODO(kallentu): Don't report error here.
1805
+ _errorReporter.reportErrorForNode (exception.errorCode, node);
1806
+ return InvalidConstant (node, exception.errorCode);
1810
1807
}
1811
- return null ;
1812
1808
}
1813
1809
1814
1810
Constant castToType (
@@ -2013,16 +2009,14 @@ class DartObjectComputer {
2013
2009
return null ;
2014
2010
}
2015
2011
2016
- DartObjectImpl ? logicalNot (
2017
- Expression node, DartObjectImpl ? evaluationResult) {
2018
- if (evaluationResult != null ) {
2019
- try {
2020
- return evaluationResult.logicalNot (_typeSystem);
2021
- } on EvaluationException catch (exception) {
2022
- _errorReporter.reportErrorForNode (exception.errorCode, node);
2023
- }
2012
+ Constant logicalNot (Expression node, DartObjectImpl evaluationResult) {
2013
+ try {
2014
+ return evaluationResult.logicalNot (_typeSystem);
2015
+ } on EvaluationException catch (exception) {
2016
+ // TODO(kallentu): Don't report error here.
2017
+ _errorReporter.reportErrorForNode (exception.errorCode, node);
2018
+ return InvalidConstant (node, exception.errorCode);
2024
2019
}
2025
- return null ;
2026
2020
}
2027
2021
2028
2022
DartObjectImpl ? logicalShiftRight (BinaryExpression node,
@@ -2049,15 +2043,14 @@ class DartObjectComputer {
2049
2043
return null ;
2050
2044
}
2051
2045
2052
- DartObjectImpl ? negated (Expression node, DartObjectImpl ? evaluationResult) {
2053
- if (evaluationResult != null ) {
2054
- try {
2055
- return evaluationResult. negated (_typeSystem);
2056
- } on EvaluationException catch (exception) {
2057
- _errorReporter.reportErrorForNode (exception.errorCode, node);
2058
- }
2046
+ Constant negated (Expression node, DartObjectImpl evaluationResult) {
2047
+ try {
2048
+ return evaluationResult. negated (_typeSystem);
2049
+ } on EvaluationException catch (exception) {
2050
+ // TODO(kallentu): Don't report error here.
2051
+ _errorReporter.reportErrorForNode (exception.errorCode, node);
2052
+ return InvalidConstant (node, exception.errorCode);
2059
2053
}
2060
- return null ;
2061
2054
}
2062
2055
2063
2056
DartObjectImpl ? notEqual (BinaryExpression node, DartObjectImpl ? leftOperand,
0 commit comments