| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 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 | 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 // Tests that malformed types are handled as dynamic, and that types with the | 5 // Tests that malformed types are handled as dynamic, and that types with the |
| 6 // wrong number of type arguments are handled as raw types. | 6 // wrong number of type arguments are handled as raw types. |
| 7 | 7 |
| 8 import 'package:expect/expect.dart'; | 8 import 'package:expect/expect.dart'; |
| 9 import 'package:expect/expect.dart' as prefix; // Define 'prefix'. |
| 9 | 10 |
| 10 checkIsUnresolved(var v) { | 11 checkIsUnresolved(var v) { |
| 11 Expect.isTrue(v is Unresolved); | 12 Expect.isTrue(v is Unresolved); |
| 12 Expect.isTrue(v is Unresolved<int>); | 13 Expect.isTrue(v is Unresolved<int>); |
| 13 Expect.isTrue(v is prefix.Unresolved); | 14 Expect.isTrue(v is prefix.Unresolved); |
| 14 Expect.isTrue(v is prefix.Unresolved<int>); | 15 Expect.isTrue(v is prefix.Unresolved<int>); |
| 15 } | 16 } |
| 16 | 17 |
| 17 checkIsListUnresolved(bool expect, var v) { | 18 checkIsListUnresolved(bool expect, var v) { |
| 18 Expect.equals(expect, v is List<Unresolved>); | 19 Expect.equals(expect, v is List<Unresolved>); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 checkAsUnresolved(''); | 70 checkAsUnresolved(''); |
| 70 checkAsUnresolved(0); | 71 checkAsUnresolved(0); |
| 71 checkAsListUnresolved(false, ''); | 72 checkAsListUnresolved(false, ''); |
| 72 checkAsListUnresolved(true, new List()); | 73 checkAsListUnresolved(true, new List()); |
| 73 checkAsListUnresolved(true, new List<int>()); | 74 checkAsListUnresolved(true, new List<int>()); |
| 74 checkAsListUnresolved(true, new List<String>()); | 75 checkAsListUnresolved(true, new List<String>()); |
| 75 checkAsListUnresolved(true, new List<int, String>()); | 76 checkAsListUnresolved(true, new List<int, String>()); |
| 76 | 77 |
| 77 checkIsListDynamic(true, []); | 78 checkIsListDynamic(true, []); |
| 78 checkIsListDynamic(true, <>[]); /// 01: compile-time error | 79 checkIsListDynamic(true, <>[]); /// 01: compile-time error |
| 79 // TODO(johnniwinther): Create runtime type information on literal lists. | 80 checkIsListDynamic(false, <int>[]); |
| 80 // checkIsListDynamic(false, <int>[]); | |
| 81 checkIsListDynamic(true, <Unresolved>[]); | 81 checkIsListDynamic(true, <Unresolved>[]); |
| 82 checkIsListDynamic(true, <Unresolved<int>>[]); | 82 checkIsListDynamic(true, <Unresolved<int>>[]); |
| 83 checkIsListDynamic(true, <prefix.Unresolved>[]); | 83 checkIsListDynamic(true, <prefix.Unresolved>[]); |
| 84 checkIsListDynamic(true, <prefix.Unresolved<int>>[]); | 84 checkIsListDynamic(true, <prefix.Unresolved<int>>[]); |
| 85 checkIsListDynamic(true, <int, String>[]); | 85 checkIsListDynamic(true, <int, String>[]); |
| 86 | 86 |
| 87 checkIsListDynamic(true, new List()); | 87 checkIsListDynamic(true, new List()); |
| 88 checkIsListDynamic(true, new List<>()); /// 02: compile-time error | 88 checkIsListDynamic(true, new List<>()); /// 02: compile-time error |
| 89 checkIsListDynamic(true, new List<Unresolved>()); | 89 checkIsListDynamic(true, new List<Unresolved>()); |
| 90 checkIsListDynamic(true, new List<Unresolved<int>>()); | 90 checkIsListDynamic(true, new List<Unresolved<int>>()); |
| 91 checkIsListDynamic(true, new List<prefix.Unresolved>()); | 91 checkIsListDynamic(true, new List<prefix.Unresolved>()); |
| 92 checkIsListDynamic(true, new List<prefix.Unresolved<int>>()); | 92 checkIsListDynamic(true, new List<prefix.Unresolved<int>>()); |
| 93 checkIsListDynamic(true, new List<int, String>()); | 93 checkIsListDynamic(true, new List<int, String>()); |
| 94 | 94 |
| 95 checkIsMapDynamic(true, true, <dynamic, dynamic>{}); |
| 95 checkIsMapDynamic(true, true, {}); | 96 checkIsMapDynamic(true, true, {}); |
| 96 checkIsMapDynamic(true, true, <>{}); /// 03: compile-time error | 97 checkIsMapDynamic(true, true, <>{}); /// 03: compile-time error |
| 97 checkIsMapDynamic(true, true, <int>{}); | 98 checkIsMapDynamic(true, true, <int>{}); |
| 98 // TODO(johnniwinther): Create runtime type information on literal maps. | 99 checkIsMapDynamic(false, false, <String, int>{}); |
| 99 // checkIsMapDynamic(false, false, <String, int>{}); | |
| 100 checkIsMapDynamic(true, true, <String, int, String>{}); | 100 checkIsMapDynamic(true, true, <String, int, String>{}); |
| 101 // checkIsMapDynamic(true, false, <Unresolved, int>{}); | 101 checkIsMapDynamic(true, false, <Unresolved, int>{}); |
| 102 // checkIsMapDynamic(false, true, <String, Unresolved<int>>{}); | 102 checkIsMapDynamic(false, true, <String, Unresolved<int>>{}); |
| 103 // checkIsMapDynamic(true, false, <prefix.Unresolved, int>{}); | 103 checkIsMapDynamic(true, false, <prefix.Unresolved, int>{}); |
| 104 // checkIsMapDynamic(false, true, <String, prefix.Unresolved<int>>{}); | 104 checkIsMapDynamic(false, true, <String, prefix.Unresolved<int>>{}); |
| 105 | 105 |
| 106 checkIsMapDynamic(true, true, new Map()); | 106 checkIsMapDynamic(true, true, new Map()); |
| 107 checkIsMapDynamic(true, true, new Map<>); /// 04: compile-time error | 107 checkIsMapDynamic(true, true, new Map<>); /// 04: compile-time error |
| 108 checkIsMapDynamic(true, true, new Map<int>()); | 108 checkIsMapDynamic(true, true, new Map<int>()); |
| 109 checkIsMapDynamic(false, false, new Map<String, int>()); | 109 checkIsMapDynamic(false, false, new Map<String, int>()); |
| 110 checkIsMapDynamic(true, true, new Map<String, int, String>()); | 110 checkIsMapDynamic(true, true, new Map<String, int, String>()); |
| 111 checkIsMapDynamic(true, false, new Map<Unresolved, int>()); | 111 checkIsMapDynamic(true, false, new Map<Unresolved, int>()); |
| 112 checkIsMapDynamic(false, true, new Map<String, Unresolved<int>>()); | 112 checkIsMapDynamic(false, true, new Map<String, Unresolved<int>>()); |
| 113 checkIsMapDynamic(true, false, new Map<prefix.Unresolved, int>()); | 113 checkIsMapDynamic(true, false, new Map<prefix.Unresolved, int>()); |
| 114 checkIsMapDynamic(false, true, new Map<String, prefix.Unresolved<int>>()); | 114 checkIsMapDynamic(false, true, new Map<String, prefix.Unresolved<int>>()); |
| 115 | 115 |
| 116 Expect.throws(() => new Unresolved(), (e) => true); | 116 Expect.throws(() => new Unresolved(), (e) => true); |
| 117 Expect.throws(() => new Unresolved<int>(), (e) => true); | 117 Expect.throws(() => new Unresolved<int>(), (e) => true); |
| 118 Expect.throws(() => new prefix.Unresolved(), (e) => true); | 118 Expect.throws(() => new prefix.Unresolved(), (e) => true); |
| 119 Expect.throws(() => new prefix.Unresolved<int>(), (e) => true); | 119 Expect.throws(() => new prefix.Unresolved<int>(), (e) => true); |
| 120 | 120 |
| 121 // The expression 'undeclared_prefix.Unresolved()' is parsed as the invocation |
| 122 // of the named constructor 'Unresolved' on the type 'undeclared_prefix'. |
| 123 Expect.throws(() => new undeclared_prefix.Unresolved(), (e) => true); |
| 124 // The expression 'undeclared_prefix.Unresolved<int>' cannot be parsed. |
| 125 Expect.throws(() => new undeclared_prefix.Unresolved<int>(), (e) => true); //
/ 05: compile-time error |
| 126 |
| 121 try { | 127 try { |
| 122 throw 'foo'; | 128 throw 'foo'; |
| 123 } on Unresolved catch (e) { | 129 } on Unresolved catch (e) { |
| 124 } catch (e) { | 130 // Equivalent to 'on dynamic', catches 'foo'. |
| 125 Expect.fail(); | |
| 126 } | 131 } |
| 127 try { | 132 try { |
| 128 throw 'foo'; | 133 throw 'foo'; |
| 129 } on Unresolved<int> catch (e) { | 134 } on Unresolved<int> catch (e) { |
| 130 } catch (e) { | 135 // Equivalent to 'on dynamic', catches 'foo'. |
| 131 Expect.fail(); | |
| 132 } | 136 } |
| 133 try { | 137 try { |
| 134 throw 'foo'; | 138 throw 'foo'; |
| 135 } on prefix.Unresolved catch (e) { | 139 } on prefix.Unresolved catch (e) { |
| 136 } catch (e) { | 140 // Equivalent to 'on dynamic', catches 'foo'. |
| 137 Expect.fail(); | |
| 138 } | 141 } |
| 139 try { | 142 try { |
| 140 throw 'foo'; | 143 throw 'foo'; |
| 141 } on prefix.Unresolved<int> catch (e) { | 144 } on prefix.Unresolved<int> catch (e) { |
| 142 } catch (e) { | 145 // Equivalent to 'on dynamic', catches 'foo'. |
| 143 Expect.fail(); | 146 } |
| 147 try { |
| 148 throw 'foo'; |
| 149 } |
| 150 on undeclared_prefix.Unresolved<int> /// 06: compile-time error |
| 151 catch (e) { |
| 144 } | 152 } |
| 145 } | 153 } |
| OLD | NEW |