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

Side by Side Diff: frog/tests/leg/src/TypeCheckerTest.dart

Issue 9835007: Typecheck constructor calls. I'm pretty sure about the call to (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests to TypeCheckerTest Created 8 years, 8 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 | « no previous file | lib/compiler/implementation/typechecker.dart » ('j') | 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) 2011, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2011, 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("../../../../lib/compiler/implementation/leg.dart"); 5 #import("../../../../lib/compiler/implementation/leg.dart");
6 #import("../../../../lib/compiler/implementation/elements/elements.dart"); 6 #import("../../../../lib/compiler/implementation/elements/elements.dart");
7 #import("../../../../lib/compiler/implementation/tree/tree.dart"); 7 #import("../../../../lib/compiler/implementation/tree/tree.dart");
8 #import('../../../../lib/compiler/implementation/scanner/scannerlib.dart'); 8 #import('../../../../lib/compiler/implementation/scanner/scannerlib.dart');
9 #import("../../../../lib/compiler/implementation/util/util.dart"); 9 #import("../../../../lib/compiler/implementation/util/util.dart");
10 #import("mock_compiler.dart"); 10 #import("mock_compiler.dart");
11 #import("parser_helper.dart"); 11 #import("parser_helper.dart");
12 12
13 Type intType; 13 Type intType;
14 Type boolType; 14 Type boolType;
15 Type stringType; 15 Type stringType;
16 Type doubleType; 16 Type doubleType;
17 Type objectType; 17 Type objectType;
18 18
19 main() { 19 main() {
20 List tests = [testSimpleTypes, 20 List tests = [testSimpleTypes,
21 testReturn, 21 testReturn,
22 testFor, 22 testFor,
23 testWhile, 23 testWhile,
24 testOperators, 24 testOperators,
25 testConstructorInvocationArgumentCount,
26 testConstructorInvocationArgumentTypes,
25 testMethodInvocationArgumentCount, 27 testMethodInvocationArgumentCount,
26 testMethodInvocations, 28 testMethodInvocations,
27 testControlFlow, 29 testControlFlow,
28 // testNewExpression, 30 // testNewExpression,
29 testConditionalExpression, 31 testConditionalExpression,
30 testIfStatement, 32 testIfStatement,
31 testThis, 33 testThis,
32 testFunctionSubtyping]; 34 testFunctionSubtyping];
33 for (Function test in tests) { 35 for (Function test in tests) {
34 setup(); 36 setup();
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 for (final op in ['>', '<', '<=', '>=', '==', '!=', '===', '!==']) { 127 for (final op in ['>', '<', '<=', '>=', '==', '!=', '===', '!==']) {
126 analyze("{ bool b = 1 ${op} 2; }"); 128 analyze("{ bool b = 1 ${op} 2; }");
127 analyze("{ int i = 1 ${op} 2; }", MessageKind.NOT_ASSIGNABLE); 129 analyze("{ int i = 1 ${op} 2; }", MessageKind.NOT_ASSIGNABLE);
128 analyze("{ int i; bool b = (i = true) ${op} 2; }", 130 analyze("{ int i; bool b = (i = true) ${op} 2; }",
129 MessageKind.NOT_ASSIGNABLE); 131 MessageKind.NOT_ASSIGNABLE);
130 analyze("{ int i; bool b = 1 ${op} (i = true); }", 132 analyze("{ int i; bool b = 1 ${op} (i = true); }",
131 MessageKind.NOT_ASSIGNABLE); 133 MessageKind.NOT_ASSIGNABLE);
132 } 134 }
133 } 135 }
134 136
137 void testConstructorInvocationArgumentCount() {
138 compiler.parseScript("""
139 class C1 { C1(x, y); }
140 class C2 { C2(int x, int y); }
141 """);
142 // calls to untyped constructor C1
143 analyze("new C1(1, 2);");
144 analyze("new C1();",
karlklose 2012/03/30 08:55:31 I think most of these would fit on one line (also
polux 2012/03/30 09:01:28 Done, I thought the layout of the other methods wa
145 MessageKind.MISSING_ARGUMENT);
146 analyze("new C1(1);",
147 MessageKind.MISSING_ARGUMENT);
148 analyze("new C1(1, 2, 3);",
149 MessageKind.ADDITIONAL_ARGUMENT);
150 analyze("new C1(1, 2);");
151 // calls to typed constructor C2
152 analyze("new C1();",
karlklose 2012/03/30 08:55:31 new C1() -> new C2() (also in l. 154 and 156). Ple
polux 2012/03/30 09:01:28 Thanks for catching that.
153 MessageKind.MISSING_ARGUMENT);
154 analyze("new C1(1);",
155 MessageKind.MISSING_ARGUMENT);
156 analyze("new C1(1, 2, 3);",
157 MessageKind.ADDITIONAL_ARGUMENT);
158 }
159
160 void testConstructorInvocationArgumentTypes() {
161 compiler.parseScript("""
162 class C1 { C1(x); }
163 class C2 { C2(int x); }
164 """);
165 analyze("new C1(42);");
166 analyze("new C1('string');");
167 analyze("new C2(42);");
168 analyze("new C2('string');",
169 MessageKind.NOT_ASSIGNABLE);
170 }
171
135 void testMethodInvocationArgumentCount() { 172 void testMethodInvocationArgumentCount() {
136 compiler.parseScript(CLASS_WITH_METHODS); 173 compiler.parseScript(CLASS_WITH_METHODS);
137 final String header = "{ ClassWithMethods c; "; 174 final String header = "{ ClassWithMethods c; ";
138 analyze("${header}c.untypedNoArgumentMethod(1); }", 175 analyze("${header}c.untypedNoArgumentMethod(1); }",
139 MessageKind.ADDITIONAL_ARGUMENT); 176 MessageKind.ADDITIONAL_ARGUMENT);
140 analyze("${header}c.untypedOneArgumentMethod(); }", 177 analyze("${header}c.untypedOneArgumentMethod(); }",
141 MessageKind.MISSING_ARGUMENT); 178 MessageKind.MISSING_ARGUMENT);
142 analyze("${header}c.untypedOneArgumentMethod(1, 1); }", 179 analyze("${header}c.untypedOneArgumentMethod(1, 1); }",
143 MessageKind.ADDITIONAL_ARGUMENT); 180 MessageKind.ADDITIONAL_ARGUMENT);
144 analyze("${header}c.untypedTwoArgumentMethod(); }", 181 analyze("${header}c.untypedTwoArgumentMethod(); }",
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 MessageKind.NOT_ASSIGNABLE); 229 MessageKind.NOT_ASSIGNABLE);
193 analyze("${header}int k = c.intOneArgumentMethod('string'); }", 230 analyze("${header}int k = c.intOneArgumentMethod('string'); }",
194 MessageKind.NOT_ASSIGNABLE); 231 MessageKind.NOT_ASSIGNABLE);
195 analyze("${header}int k = c.intOneArgumentMethod(i); }"); 232 analyze("${header}int k = c.intOneArgumentMethod(i); }");
196 233
197 analyze("${header}int k = c.intTwoArgumentMethod(1, 'string'); }", 234 analyze("${header}int k = c.intTwoArgumentMethod(1, 'string'); }",
198 MessageKind.NOT_ASSIGNABLE); 235 MessageKind.NOT_ASSIGNABLE);
199 analyze("${header}int k = c.intTwoArgumentMethod(i, j); }"); 236 analyze("${header}int k = c.intTwoArgumentMethod(i, j); }");
200 analyze("${header}ClassWithMethods x = c.intTwoArgumentMethod(i, j); }", 237 analyze("${header}ClassWithMethods x = c.intTwoArgumentMethod(i, j); }",
201 MessageKind.NOT_ASSIGNABLE); 238 MessageKind.NOT_ASSIGNABLE);
239
240 analyze("${header}c.intField(); }",
241 MessageKind.METHOD_NOT_FOUND);
242 analyze("${header}d.intField(); }",
243 MessageKind.METHOD_NOT_FOUND);
244
202 } 245 }
203 246
204 /** Tests analysis of returns (not required by the specification). */ 247 /** Tests analysis of returns (not required by the specification). */
205 void testControlFlow() { 248 void testControlFlow() {
206 analyzeTopLevel("int foo() { if (true) { return 1; } }", 249 analyzeTopLevel("int foo() { if (true) { return 1; } }",
207 MessageKind.MAYBE_MISSING_RETURN); 250 MessageKind.MAYBE_MISSING_RETURN);
208 final bar = 251 final bar =
209 """void bar() { 252 """void bar() {
210 if (true) { 253 if (true) {
211 if (true) { return; } else { return; } 254 if (true) { return; } else { return; }
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 parser.parseStatement(tokens); 466 parser.parseStatement(tokens);
424 Node node = listener.popNode(); 467 Node node = listener.popNode();
425 TreeElements elements = compiler.resolveNodeStatement(node, classElement); 468 TreeElements elements = compiler.resolveNodeStatement(node, classElement);
426 TypeCheckerVisitor checker = new TypeCheckerVisitor(compiler, elements, 469 TypeCheckerVisitor checker = new TypeCheckerVisitor(compiler, elements,
427 types); 470 types);
428 compiler.clearWarnings(); 471 compiler.clearWarnings();
429 checker.currentClass = classElement; 472 checker.currentClass = classElement;
430 checker.analyze(node); 473 checker.analyze(node);
431 compareWarningKinds(text, expectedWarnings, compiler.warnings); 474 compareWarningKinds(text, expectedWarnings, compiler.warnings);
432 } 475 }
OLDNEW
« no previous file with comments | « no previous file | lib/compiler/implementation/typechecker.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698