Fix a corner case of constant constructor dependency computation.

If a constant constructor does not contain an explicit call to
super(), and the base class lacks an explicit constructor, we need to
avoid marking the implicit base class constructor as a dependency,
since it is non-const.  (Note: this shouldn't occur very often in
real-world usage since is a compile-time error, but we still need to
be able to analyze it without throwing an exception).

Fixes the following test when the new task model is switched on:
co19/Language/07_Classes/6_Constructors/3_Constant_Constructors_A03_t02

R=brianwilkerson@google.com

Review URL: https://codereview.chromium.org//1168563004
This commit is contained in:
Paul Berry 2015-06-08 11:23:32 -07:00
parent b916cbffa4
commit 12696cafe9
2 changed files with 16 additions and 1 deletions

View file

@ -457,7 +457,7 @@ class ConstantEvaluationEngine {
if (superclass != null && !superclass.isObject) {
ConstructorElement unnamedConstructor = ConstantEvaluationEngine
._getConstructorBase(superclass.element.unnamedConstructor);
if (unnamedConstructor != null) {
if (unnamedConstructor != null && unnamedConstructor.isConst) {
callback(unnamedConstructor);
}
}

View file

@ -1495,6 +1495,21 @@ const d = a;
''');
}
test_const_constructor_calls_implicit_super_constructor_implicitly() {
// Note: the situation below is a compile-time error (since the synthetic
// constructor for Base is non-const), but we need to handle it without
// throwing an exception.
EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue(
'x', '''
class Base {}
class Derived extends Base {
const Derived();
}
const x = const Derived();
''');
expect(evaluationResult, isNotNull);
}
test_dependency() {
EvaluationResultImpl evaluationResult = _computeTopLevelVariableConstValue(
'x', '''