Fix LUB computation in face of errors in code (issue 26631)

R=scheglov@google.com

Review URL: https://codereview.chromium.org/2043173002 .
This commit is contained in:
Brian Wilkerson 2016-06-08 07:54:54 -07:00
parent a66d2d0e49
commit 27c0eeb0b2
2 changed files with 38 additions and 6 deletions

View file

@ -662,8 +662,12 @@ class StaticTypeAnalyzer extends SimpleAstVisitor<Object> {
// elements
if (node.elements.isNotEmpty) {
// Infer the list type from the arguments.
DartType staticType =
node.elements.map((e) => e.staticType).reduce(_leastUpperBound);
Iterable<DartType> types =
node.elements.map((e) => e.staticType).where((t) => t != null);
if (types.isEmpty) {
return null;
}
DartType staticType = types.reduce(_leastUpperBound);
if (staticType.isBottom) {
staticType = _dynamicType;
}

View file

@ -1078,6 +1078,29 @@ class StaticTypeAnalyzerTest extends EngineTestCase {
_listener.assertNoErrors();
}
void test_visitListLiteral_unresolved() {
_analyzer = _createAnalyzer(strongMode: true);
// [a] // where 'a' is not resolved
Identifier identifier = AstFactory.identifier3('a');
Expression node = AstFactory.listLiteral([identifier]);
DartType resultType = _analyze(node);
expect(resultType, isNull);
_listener.assertNoErrors();
}
void test_visitListLiteral_unresolved_multiple() {
_analyzer = _createAnalyzer(strongMode: true);
// [0, a, 1] // where 'a' is not resolved
Identifier identifier = AstFactory.identifier3('a');
Expression node = AstFactory
.listLiteral([_resolvedInteger(0), identifier, _resolvedInteger(1)]);
DartType resultType = _analyze(node);
_assertType2(
_typeProvider.listType.instantiate(<DartType>[_typeProvider.intType]),
resultType);
_listener.assertNoErrors();
}
void test_visitMapLiteral_empty() {
// {}
Expression node = AstFactory.mapLiteral2();
@ -1488,11 +1511,16 @@ class StaticTypeAnalyzerTest extends EngineTestCase {
/**
* Create the analyzer used by the tests.
*
* @return the analyzer to be used by the tests
*/
StaticTypeAnalyzer _createAnalyzer() {
InternalAnalysisContext context = AnalysisContextFactory.contextWithCore();
StaticTypeAnalyzer _createAnalyzer({bool strongMode: false}) {
InternalAnalysisContext context;
if (strongMode) {
AnalysisOptionsImpl options = new AnalysisOptionsImpl();
options.strongMode = true;
context = AnalysisContextFactory.contextWithCoreAndOptions(options);
} else {
context = AnalysisContextFactory.contextWithCore();
}
FileBasedSource source =
new FileBasedSource(FileUtilities2.createFile("/lib.dart"));
CompilationUnitElementImpl definingCompilationUnit =