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

Side by Side Diff: tests/language/ref_before_declaration_test.dart

Issue 51533003: Compile time error if name is used before variable is declared (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 1 month 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
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
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.
4
5 // Test compile-time errors for illegal variable declarations if the name
6 // has been referenced before the variable is declared.
7
8 import 'dart:math' as math;
9
10 use(value) => value;
11
12 var x = 0;
13 final y = 0;
14
15 class C {
16 var f;
17 C() : f = 'How do you spell PTSD?';
18
19 void test1() {
20 use(f); // Refers to instance field f.
21 var f = 'A shut mouth gathers no foot.'; /// 00: compile-time error
22 }
23
24 void test2() {
25 void localFunc() {
26 use(f); // Refers to instance field f.
27 }
28
29 var f = 'When chemists die, they barium.'; /// 01: compile-time error
30 if (true) {
31 var f = 1; // ok, shadows outer f and instance field f.
32 }
33 }
34
35 void test3() {
36 if (true) {
37 use(x); // Refers to top-level x.
38 use(y); // Refers to top-level y.
39 }
40 final x = "I have not yet begun to procrastinate."; /// 02: compile-time er ror
41 const y = "Honk if you like peace and quiet!"; /// 03: compile-time error
42 }
43
44 test() {
45 test1();
46 test2();
47 test3();
48 }
49 }
50
51 void testTypeRef() {
52 String s = 'Can vegetarians eat animal crackers?';
53 var String = "I distinctly remember forgetting that."; /// 04: compile-time e rror
54 }
55
56 void testLibPrefix() {
57 var pie = math.PI;
58 final math = 0; /// 05: compile-time error
59 }
60
61
62 void noErrorsExpected() {
63 use(x);
64 for (var x = 0; x < 10; x++) use(x);
65 for (var i = 0; i < 10; i++) var x = 0;
66 if (true) var x = 0;
67 while (false) var x = 0;
68 try { throw "ball"; } catch (x) { use(x); }
69 switch (x) {
70 case 0: var x = 'Does fuzzy logic tickle?';
71 }
72 var int = 007;
73 }
74
75 void main() {
76 var c = new C();
77 c.test();
78 testTypeRef();
79 testLibPrefix();
80 noErrorsExpected();
81 }
OLDNEW
« tests/language/bailout3_test.dart ('K') | « tests/language/prefix9_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698