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

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

Issue 19097003: Support new malformed types semantics. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 7 years, 5 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
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 // Unresolved imported symbols are handled differently in production mode and 5 // Unresolved imported symbols are treated as dynamic
6 // check modes. In this test, the function myFunc is malformed, because 6 // In this test, the function myFunc contains malformed types because
7 // lib12.Library13 is not resolved. 7 // lib12.Library13 is not resolved.
8 // In checked mode, the assignment type check throws a run time type error.
9 // In production, no assignment type checks are performed.
10 8
11 library Prefix16NegativeTest.dart; 9 library Prefix16NegativeTest.dart;
12 import "package:expect/expect.dart"; 10 import "package:expect/expect.dart";
13 import "library12.dart" as lib12; 11 import "library12.dart" as lib12;
14 12
15 typedef lib12.Library13 myFunc(lib12.Library13 param); 13 typedef lib12.Library13 myFunc(lib12.Library13 param);
16 14
17 isCheckedMode() { 15 isCheckedMode() {
18 try { 16 try {
19 var i = 1; 17 var i = 1;
20 String s = i; 18 String s = i;
21 return false; 19 return false;
22 } catch (e) { 20 } catch (e) {
23 return true; 21 return true;
24 } 22 }
25 } 23 }
26 24
27 main() { 25 main() {
28 { 26 {
29 bool got_type_error = false; 27 bool got_type_error = false;
30 try { 28 try {
29 // Malformed myFunc treated as (dynamic) => dynamic.
karlklose 2013/07/19 11:45:40 Do we have tests for functions with malformed and
Johnni Winther 2013/07/29 09:59:48 Extended this test.
31 myFunc i = 0; 30 myFunc i = 0;
32 } on TypeError catch (error) { 31 } on TypeError catch (error) {
33 got_type_error = true; 32 got_type_error = true;
34 } 33 }
35 // Type error in checked mode only. 34 // Type error in checked mode only.
36 Expect.isTrue(got_type_error == isCheckedMode()); 35 Expect.isTrue(got_type_error == isCheckedMode());
37 } 36 }
38 { 37 {
39 bool got_type_error = false; 38 bool got_type_error = false;
40 try { 39 try {
41 // In production mode, malformed myFunc is mapped to (dynamic) => dynamic. 40 // Malformed myFunc treated as (dynamic) => dynamic.
42 Expect.isTrue(((int x) => x) is myFunc); 41 Expect.isTrue(((int x) => x) is myFunc);
43 } on TypeError catch (error) { 42 } on TypeError catch (error) {
44 got_type_error = true; 43 got_type_error = true;
45 } 44 }
46 // Type error in checked mode only. 45 // Type error in checked mode only.
karlklose 2013/07/19 11:45:40 Update comment. You could also fail directly in t
Johnni Winther 2013/07/29 09:59:48 Done.
47 Expect.isTrue(got_type_error == isCheckedMode()); 46 Expect.isFalse(got_type_error);
48 } 47 }
49 } 48 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698