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

Side by Side Diff: dart/tests/compiler/dart2js/resolver_test.dart

Issue 821593004: Create erroneous element when resolution of initializer fails. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Tests passing locally. Created 5 years, 11 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « dart/pkg/compiler/lib/src/typechecker.dart ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 import "package:expect/expect.dart"; 5 import "package:expect/expect.dart";
6 import 'dart:async'; 6 import 'dart:async';
7 import "package:async_helper/async_helper.dart"; 7 import "package:async_helper/async_helper.dart";
8 import 'dart:collection'; 8 import 'dart:collection';
9 9
10 import "package:compiler/src/resolution/resolution.dart"; 10 import "package:compiler/src/resolution/resolution.dart";
11 import "compiler_helper.dart"; 11 import "compiler_helper.dart";
12 import "parser_helper.dart"; 12 import "parser_helper.dart";
13 13
14 import 'package:compiler/src/dart_types.dart'; 14 import 'package:compiler/src/dart_types.dart';
15 import 'package:compiler/src/elements/modelx.dart'; 15 import 'package:compiler/src/elements/modelx.dart';
16 import 'link_helper.dart'; 16 import 'link_helper.dart';
17 17
18 import "package:compiler/src/dart2jslib.dart" show
19 CompilerCancelledException;
20
21 Node buildIdentifier(String name) => new Identifier(scan(name)); 18 Node buildIdentifier(String name) => new Identifier(scan(name));
22 19
23 Node buildInitialization(String name) => 20 Node buildInitialization(String name) =>
24 parseBodyCode('$name = 1', 21 parseBodyCode('$name = 1',
25 (parser, tokens) => parser.parseOptionallyInitializedIdentifier(tokens)); 22 (parser, tokens) => parser.parseOptionallyInitializedIdentifier(tokens));
26 23
27 createLocals(List variables) { 24 createLocals(List variables) {
28 var locals = <Node>[]; 25 var locals = <Node>[];
29 for (final variable in variables) { 26 for (final variable in variables) {
30 String name = variable[0]; 27 String name = variable[0];
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 MockCompiler.create((MockCompiler compiler) { 271 MockCompiler.create((MockCompiler compiler) {
275 compiler.parseScript("class Foo { static foo() { return this; } }"); 272 compiler.parseScript("class Foo { static foo() { return this; } }");
276 compiler.resolveStatement("Foo foo;"); 273 compiler.resolveStatement("Foo foo;");
277 ClassElement fooElement = compiler.mainApp.find("Foo"); 274 ClassElement fooElement = compiler.mainApp.find("Foo");
278 FunctionElement funElement = fooElement.lookupLocalMember("foo"); 275 FunctionElement funElement = fooElement.lookupLocalMember("foo");
279 ResolverVisitor visitor = new ResolverVisitor(compiler, funElement, 276 ResolverVisitor visitor = new ResolverVisitor(compiler, funElement,
280 new ResolutionRegistry.internal(compiler, 277 new ResolutionRegistry.internal(compiler,
281 new CollectingTreeElements(funElement))); 278 new CollectingTreeElements(funElement)));
282 FunctionExpression function = 279 FunctionExpression function =
283 (funElement as FunctionElementX).parseNode(compiler); 280 (funElement as FunctionElementX).parseNode(compiler);
284 try { 281 visitor.visit(function.body);
285 visitor.visit(function.body);
286 } on CompilerCancelledException catch (_) {
287 // Ignored.
288
289 // TODO(ahe): Don't ignore CompilerCancelledException, instead, fix
290 // pkg/compiler/lib/src/resolution/members.dart.
291 }
292 Expect.equals(0, compiler.warnings.length); 282 Expect.equals(0, compiler.warnings.length);
293 Expect.equals(1, compiler.errors.length); 283 Expect.equals(1, compiler.errors.length);
294 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE, 284 Expect.equals(MessageKind.NO_INSTANCE_AVAILABLE,
295 compiler.errors[0].message.kind); 285 compiler.errors[0].message.kind);
296 }), 286 }),
297 ]); 287 ]);
298 } 288 }
299 289
300 Future testLocalsOne() { 290 Future testLocalsOne() {
301 return Future.forEach([ 291 return Future.forEach([
(...skipping 399 matching lines...) Expand 10 before | Expand all | Expand 10 after
701 } else { 691 } else {
702 element = classElement.lookupConstructor( 692 element = classElement.lookupConstructor(
703 new Selector.callDefaultConstructor(classElement.library)); 693 new Selector.callDefaultConstructor(classElement.library));
704 } 694 }
705 695
706 FunctionExpression tree = (element as FunctionElement).node; 696 FunctionExpression tree = (element as FunctionElement).node;
707 ResolverVisitor visitor = 697 ResolverVisitor visitor =
708 new ResolverVisitor(compiler, element, 698 new ResolverVisitor(compiler, element,
709 new ResolutionRegistry.internal(compiler, 699 new ResolutionRegistry.internal(compiler,
710 new CollectingTreeElements(element))); 700 new CollectingTreeElements(element)));
711 try { 701 new InitializerResolver(visitor).resolveInitializers(element, tree);
712 new InitializerResolver(visitor).resolveInitializers(element, tree);
713 } on CompilerCancelledException catch (_) {
714 // Ignored.
715
716 // TODO(ahe): Don't ignore CompilerCancelledException, instead, fix
717 // pkg/compiler/lib/src/resolution/members.dart.
718 }
719
720 visitor.visit(tree.body); 702 visitor.visit(tree.body);
721 Expect.equals(expectedElementCount, map(visitor).length); 703 Expect.equals(expectedElementCount, map(visitor).length);
722 704
723 compareWarningKinds(script, expectedWarnings, compiler.warnings); 705 compareWarningKinds(script, expectedWarnings, compiler.warnings);
724 compareWarningKinds(script, expectedErrors, compiler.errors); 706 compareWarningKinds(script, expectedErrors, compiler.errors);
725 compareWarningKinds(script, expectedInfos, compiler.infos); 707 compareWarningKinds(script, expectedInfos, compiler.infos);
726 }); 708 });
727 } 709 }
728 710
729 Future testClassHierarchy() { 711 Future testClassHierarchy() {
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after
930 }"""; 912 }""";
931 return resolveConstructor(script, "A a = new A();", "A", "", 2, 913 return resolveConstructor(script, "A a = new A();", "A", "", 2,
932 expectedInfos: [MessageKind.ALREADY_INITIALIZED], 914 expectedInfos: [MessageKind.ALREADY_INITIALIZED],
933 expectedErrors: [MessageKind.DUPLICATE_INITIALIZER]); 915 expectedErrors: [MessageKind.DUPLICATE_INITIALIZER]);
934 }, 916 },
935 () { 917 () {
936 String script = 918 String script =
937 """class A { 919 """class A {
938 A() : this.foo = 1; 920 A() : this.foo = 1;
939 }"""; 921 }""";
940 return resolveConstructor(script, "A a = new A();", "A", "", 0, 922 return resolveConstructor(script, "A a = new A();", "A", "", 1,
941 expectedWarnings: [], 923 expectedWarnings: [],
942 expectedErrors: [MessageKind.CANNOT_RESOLVE]); 924 expectedErrors: [MessageKind.CANNOT_RESOLVE]);
943 }, 925 },
944 () { 926 () {
945 String script = 927 String script =
946 """class A { 928 """class A {
947 int foo; 929 int foo;
948 int bar; 930 int bar;
949 A() : this.foo = bar; 931 A() : this.foo = bar;
950 }"""; 932 }""";
(...skipping 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
1160 }"""; 1142 }""";
1161 asyncTest(() => compileScript(script2).then((compiler) { 1143 asyncTest(() => compileScript(script2).then((compiler) {
1162 expect(compiler, 1144 expect(compiler,
1163 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS], 1145 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS],
1164 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, 1146 [MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR,
1165 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR, 1147 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_CONSTRUCTOR,
1166 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD, 1148 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD,
1167 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD]); 1149 MessageKind.CONST_CONSTRUCTOR_WITH_NONFINAL_FIELDS_FIELD]);
1168 })); 1150 }));
1169 } 1151 }
OLDNEW
« no previous file with comments | « dart/pkg/compiler/lib/src/typechecker.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698