OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 /// Dart test verifying that method type variables are considered to denote | 5 /// Dart test verifying that method type variables are considered to denote |
6 /// the type `dynamic`. | 6 /// the type `dynamic`. |
7 /// | 7 /// |
8 /// NB: This test is intended to succeed with a `dart2js` with the option | 8 /// NB: This test is intended to succeed with a `dart2js` with the option |
9 /// '--generic-method-syntax', but it should fail with a full implementation | 9 /// '--generic-method-syntax', but it should fail with a full implementation |
10 /// of generic method support, and it should fail with every other tool than | 10 /// of generic method support, and it should fail with every other tool than |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 new C().aMethod<Set>(); | 62 new C().aMethod<Set>(); |
63 } | 63 } |
64 ''', | 64 ''', |
65 'cannot_new_function_type_variable.dart': ''' | 65 'cannot_new_function_type_variable.dart': ''' |
66 X aFunction<X>() => new X(42); | 66 X aFunction<X>() => new X(42); |
67 | 67 |
68 main() { | 68 main() { |
69 aFunction<Set>(); | 69 aFunction<Set>(); |
70 } | 70 } |
71 ''', | 71 ''', |
| 72 |
| 73 'dynamic_as_type_argument.dart': ''' |
| 74 main() { |
| 75 method<dynamic>(); |
| 76 } |
| 77 method<T>() {} |
| 78 ''', |
72 }; | 79 }; |
73 | 80 |
74 Future runTest(Uri main, {MessageKind warning, MessageKind info}) async { | 81 Future runTest(Uri main, {MessageKind warning, MessageKind info}) async { |
75 print("----\nentry-point: $main\n"); | 82 print("----\nentry-point: $main\n"); |
76 | 83 |
77 DiagnosticCollector diagnostics = new DiagnosticCollector(); | 84 DiagnosticCollector diagnostics = new DiagnosticCollector(); |
78 OutputCollector output = new OutputCollector(); | 85 OutputCollector output = new OutputCollector(); |
79 await runCompiler( | 86 await runCompiler( |
80 entryPoint: main, | 87 entryPoint: main, |
81 options: const <String>["--generic-method-syntax"], | 88 options: const <String>["--generic-method-syntax"], |
82 memorySourceFiles: MEMORY_SOURCE_FILES, | 89 memorySourceFiles: MEMORY_SOURCE_FILES, |
83 diagnosticHandler: diagnostics, | 90 diagnosticHandler: diagnostics, |
84 outputProvider: output); | 91 outputProvider: output); |
85 | 92 |
86 Expect.isFalse(output.hasExtraOutput); | 93 Expect.isFalse(output.hasExtraOutput); |
87 Expect.equals(0, diagnostics.errors.length); | 94 Expect.equals(0, diagnostics.errors.length, "Unexpected errors."); |
88 Expect.equals(warning != null ? 1 : 0, diagnostics.warnings.length); | 95 Expect.equals(warning != null ? 1 : 0, diagnostics.warnings.length); |
89 if (warning != null) { | 96 if (warning != null) { |
90 Expect.equals(warning, diagnostics.warnings.first.message.kind); | 97 Expect.equals(warning, diagnostics.warnings.first.message.kind); |
91 } | 98 } |
92 Expect.equals(info != null ? 1 : 0, diagnostics.infos.length); | 99 Expect.equals(info != null ? 1 : 0, diagnostics.infos.length); |
93 if (info != null) { | 100 if (info != null) { |
94 Expect.equals(info, diagnostics.infos.first.message.kind); | 101 Expect.equals(info, diagnostics.infos.first.message.kind); |
95 } | 102 } |
96 Expect.equals(0, diagnostics.hints.length); | 103 Expect.equals(0, diagnostics.hints.length); |
97 } | 104 } |
98 | 105 |
99 void main() { | 106 void main() { |
100 asyncTest(() async { | 107 asyncTest(() async { |
101 await runTest(Uri.parse('memory:type_variable_is_dynamic.dart')); | 108 await runTest(Uri.parse('memory:type_variable_is_dynamic.dart')); |
102 | 109 |
103 await runTest(Uri.parse('memory:cannot_new_method_type_variable.dart'), | 110 await runTest(Uri.parse('memory:cannot_new_method_type_variable.dart'), |
104 warning: MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE); | 111 warning: MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE); |
105 | 112 |
106 await runTest(Uri.parse('memory:cannot_new_function_type_variable.dart'), | 113 await runTest(Uri.parse('memory:cannot_new_function_type_variable.dart'), |
107 warning: MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE); | 114 warning: MessageKind.CANNOT_INSTANTIATE_TYPE_VARIABLE); |
| 115 |
| 116 await runTest(Uri.parse('memory:dynamic_as_type_argument.dart')); |
108 }); | 117 }); |
109 } | 118 } |
OLD | NEW |