OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library analyzer.test.generated.static_type_analyzer_test; | 5 library analyzer.test.generated.static_type_analyzer_test; |
6 | 6 |
7 import 'dart:collection'; | 7 import 'dart:collection'; |
8 | 8 |
9 import 'package:analyzer/dart/ast/ast.dart'; | 9 import 'package:analyzer/dart/ast/ast.dart'; |
10 import 'package:analyzer/dart/ast/token.dart'; | 10 import 'package:analyzer/dart/ast/token.dart'; |
(...skipping 1060 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1071 // [0] | 1071 // [0] |
1072 Expression node = AstFactory.listLiteral([_resolvedInteger(0)]); | 1072 Expression node = AstFactory.listLiteral([_resolvedInteger(0)]); |
1073 DartType resultType = _analyze(node); | 1073 DartType resultType = _analyze(node); |
1074 _assertType2( | 1074 _assertType2( |
1075 _typeProvider.listType | 1075 _typeProvider.listType |
1076 .instantiate(<DartType>[_typeProvider.dynamicType]), | 1076 .instantiate(<DartType>[_typeProvider.dynamicType]), |
1077 resultType); | 1077 resultType); |
1078 _listener.assertNoErrors(); | 1078 _listener.assertNoErrors(); |
1079 } | 1079 } |
1080 | 1080 |
| 1081 void test_visitListLiteral_unresolved() { |
| 1082 _analyzer = _createAnalyzer(strongMode: true); |
| 1083 // [a] // where 'a' is not resolved |
| 1084 Identifier identifier = AstFactory.identifier3('a'); |
| 1085 Expression node = AstFactory.listLiteral([identifier]); |
| 1086 DartType resultType = _analyze(node); |
| 1087 expect(resultType, isNull); |
| 1088 _listener.assertNoErrors(); |
| 1089 } |
| 1090 |
| 1091 void test_visitListLiteral_unresolved_multiple() { |
| 1092 _analyzer = _createAnalyzer(strongMode: true); |
| 1093 // [0, a, 1] // where 'a' is not resolved |
| 1094 Identifier identifier = AstFactory.identifier3('a'); |
| 1095 Expression node = AstFactory.listLiteral([_resolvedInteger(0), identifier, _
resolvedInteger(1)]); |
| 1096 DartType resultType = _analyze(node); |
| 1097 _assertType2( |
| 1098 _typeProvider.listType |
| 1099 .instantiate(<DartType>[_typeProvider.intType]), |
| 1100 resultType); |
| 1101 _listener.assertNoErrors(); |
| 1102 } |
| 1103 |
1081 void test_visitMapLiteral_empty() { | 1104 void test_visitMapLiteral_empty() { |
1082 // {} | 1105 // {} |
1083 Expression node = AstFactory.mapLiteral2(); | 1106 Expression node = AstFactory.mapLiteral2(); |
1084 DartType resultType = _analyze(node); | 1107 DartType resultType = _analyze(node); |
1085 _assertType2( | 1108 _assertType2( |
1086 _typeProvider.mapType.instantiate( | 1109 _typeProvider.mapType.instantiate( |
1087 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]), | 1110 <DartType>[_typeProvider.dynamicType, _typeProvider.dynamicType]), |
1088 resultType); | 1111 resultType); |
1089 _listener.assertNoErrors(); | 1112 _listener.assertNoErrors(); |
1090 } | 1113 } |
(...skipping 390 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1481 EngineTestCase.assertInstanceOf( | 1504 EngineTestCase.assertInstanceOf( |
1482 (obj) => obj is InterfaceTypeImpl, InterfaceTypeImpl, actualType); | 1505 (obj) => obj is InterfaceTypeImpl, InterfaceTypeImpl, actualType); |
1483 _assertType(expectedType, actualType as InterfaceTypeImpl); | 1506 _assertType(expectedType, actualType as InterfaceTypeImpl); |
1484 } | 1507 } |
1485 // TODO(brianwilkerson) Compare other kinds of types then make this a shared | 1508 // TODO(brianwilkerson) Compare other kinds of types then make this a shared |
1486 // utility method. | 1509 // utility method. |
1487 } | 1510 } |
1488 | 1511 |
1489 /** | 1512 /** |
1490 * Create the analyzer used by the tests. | 1513 * Create the analyzer used by the tests. |
1491 * | |
1492 * @return the analyzer to be used by the tests | |
1493 */ | 1514 */ |
1494 StaticTypeAnalyzer _createAnalyzer() { | 1515 StaticTypeAnalyzer _createAnalyzer({bool strongMode: false}) { |
1495 InternalAnalysisContext context = AnalysisContextFactory.contextWithCore(); | 1516 InternalAnalysisContext context; |
| 1517 if (strongMode) { |
| 1518 AnalysisOptionsImpl options = new AnalysisOptionsImpl(); |
| 1519 options.strongMode = true; |
| 1520 context = AnalysisContextFactory.contextWithCoreAndOptions(options); |
| 1521 } else { |
| 1522 context = AnalysisContextFactory.contextWithCore(); |
| 1523 } |
1496 FileBasedSource source = | 1524 FileBasedSource source = |
1497 new FileBasedSource(FileUtilities2.createFile("/lib.dart")); | 1525 new FileBasedSource(FileUtilities2.createFile("/lib.dart")); |
1498 CompilationUnitElementImpl definingCompilationUnit = | 1526 CompilationUnitElementImpl definingCompilationUnit = |
1499 new CompilationUnitElementImpl("lib.dart"); | 1527 new CompilationUnitElementImpl("lib.dart"); |
1500 definingCompilationUnit.librarySource = | 1528 definingCompilationUnit.librarySource = |
1501 definingCompilationUnit.source = source; | 1529 definingCompilationUnit.source = source; |
1502 LibraryElementImpl definingLibrary = | 1530 LibraryElementImpl definingLibrary = |
1503 new LibraryElementImpl.forNode(context, null); | 1531 new LibraryElementImpl.forNode(context, null); |
1504 definingLibrary.definingCompilationUnit = definingCompilationUnit; | 1532 definingLibrary.definingCompilationUnit = definingCompilationUnit; |
1505 _typeProvider = new TestTypeProvider(context); | 1533 _typeProvider = new TestTypeProvider(context); |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1627 void _setType(FormalParameter parameter, DartType type) { | 1655 void _setType(FormalParameter parameter, DartType type) { |
1628 SimpleIdentifier identifier = parameter.identifier; | 1656 SimpleIdentifier identifier = parameter.identifier; |
1629 Element element = identifier.staticElement; | 1657 Element element = identifier.staticElement; |
1630 if (element is! ParameterElement) { | 1658 if (element is! ParameterElement) { |
1631 element = new ParameterElementImpl.forNode(identifier); | 1659 element = new ParameterElementImpl.forNode(identifier); |
1632 identifier.staticElement = element; | 1660 identifier.staticElement = element; |
1633 } | 1661 } |
1634 (element as ParameterElementImpl).type = type; | 1662 (element as ParameterElementImpl).type = type; |
1635 } | 1663 } |
1636 } | 1664 } |
OLD | NEW |