Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(377)

Unified Diff: tests/compiler/dart2js/type_checker_test.dart

Issue 15759011: Type check field initializers. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Test added. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « tests/compiler/dart2js/patch_test.dart ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/compiler/dart2js/type_checker_test.dart
diff --git a/tests/compiler/dart2js/type_checker_test.dart b/tests/compiler/dart2js/type_checker_test.dart
index c9c0221a7da689839add710c6eab168287cfa3d9..429279384f47226c7dcb087826fd62d855576181 100644
--- a/tests/compiler/dart2js/type_checker_test.dart
+++ b/tests/compiler/dart2js/type_checker_test.dart
@@ -44,7 +44,8 @@ main() {
testIfStatement,
testThis,
testSuper,
- testOperatorsAssignability];
+ testOperatorsAssignability,
+ testFieldInitializers];
for (Function test in tests) {
setup();
test();
@@ -846,6 +847,19 @@ testOperatorsAssignability() {
[MessageKind.NOT_ASSIGNABLE, MessageKind.NOT_ASSIGNABLE]);
}
+void testFieldInitializers() {
+ analyzeTopLevel("""int i = 0;""");
+ analyzeTopLevel("""int i = '';""", MessageKind.NOT_ASSIGNABLE);
+
+ analyzeTopLevel("""class Class {
+ int i = 0;
+ }""");
+ analyzeTopLevel("""class Class {
+ int i = '';
+ }""", MessageKind.NOT_ASSIGNABLE);
+}
+
+
const CLASS_WITH_METHODS = '''
class ClassWithMethods {
untypedNoArgumentMethod() {}
@@ -941,6 +955,8 @@ analyzeTopLevel(String text, [expectedWarnings]) {
if (expectedWarnings == null) expectedWarnings = [];
if (expectedWarnings is !List) expectedWarnings = [expectedWarnings];
+ compiler.diagnosticHandler = createHandler(text);
+
LibraryElement library = mockLibrary(compiler, text);
Link<Element> topLevelElements = parseUnit(text, compiler, library);
@@ -948,14 +964,22 @@ analyzeTopLevel(String text, [expectedWarnings]) {
for (Link<Element> elements = topLevelElements;
!elements.isEmpty;
elements = elements.tail) {
- Node node = elements.head.parseNode(compiler);
- TreeElements mapping = compiler.resolver.resolve(elements.head);
+ Element element = elements.head;
+ if (element.isClass()) {
+ ClassElement classElement = element;
+ classElement.ensureResolved(compiler);
+ // Analyze last class member.
+ classElement.forEachLocalMember((Element e) => element = e);
+ }
+ Node node = element.parseNode(compiler);
+ TreeElements mapping = compiler.resolver.resolve(element);
TypeCheckerVisitor checker =
new TypeCheckerVisitor(compiler, mapping, types);
compiler.clearWarnings();
checker.analyze(node);
compareWarningKinds(text, expectedWarnings, compiler.warnings);
}
+ compiler.diagnosticHandler = null;
}
api.DiagnosticHandler createHandler(String text) {
« no previous file with comments | « tests/compiler/dart2js/patch_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698