File tree 2 files changed +23
-2
lines changed
2 files changed +23
-2
lines changed Original file line number Diff line number Diff line change @@ -1608,8 +1608,9 @@ class ConstantVisitor extends UnifyingAstVisitor<DartObjectImpl> {
1608
1608
// Driver, we compute values of all dependencies first (or detect cycle).
1609
1609
// So, the value has already been computed. Just return it.
1610
1610
if (evaluationEngine.forAnalysisDriver) {
1611
- if (variableElement.isConst) {
1612
- return variableElement.evaluationResult.value;
1611
+ EvaluationResultImpl value = variableElement.evaluationResult;
1612
+ if (variableElement.isConst && value != null ) {
1613
+ return value.value;
1613
1614
}
1614
1615
} else {
1615
1616
// TODO(scheglov) Once we remove task model, we can remove this code.
Original file line number Diff line number Diff line change 3
3
// BSD-style license that can be found in the LICENSE file.
4
4
5
5
import 'package:analyzer/src/dart/element/element.dart' ;
6
+ import 'package:analyzer/src/error/codes.dart' ;
6
7
import 'package:test/test.dart' ;
7
8
import 'package:test_reflective_loader/test_reflective_loader.dart' ;
8
9
@@ -130,6 +131,25 @@ main() {}
130
131
var value = node.elementAnnotation.constantValue;
131
132
expect (value.getField ('(super)' ).getField ('f' ).toIntValue (), 42 );
132
133
}
134
+
135
+ test_constNotInitialized () async {
136
+ addTestFile (r'''
137
+ class B {
138
+ const B(_);
139
+ }
140
+
141
+ class C extends B {
142
+ static const a;
143
+ const C() : super(a);
144
+ }
145
+ ''' );
146
+ await resolveTestFile ();
147
+ assertTestErrors ([
148
+ CompileTimeErrorCode .NON_CONSTANT_VALUE_IN_INITIALIZER ,
149
+ CompileTimeErrorCode .CONST_NOT_INITIALIZED ,
150
+ CompileTimeErrorCode .CONST_NOT_INITIALIZED ,
151
+ ]);
152
+ }
133
153
}
134
154
135
155
@reflectiveTest
You can’t perform that action at this time.
0 commit comments