| OLD | NEW |
| 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 // Dart test program for testing named parameters. | 4 // Dart test program for testing named parameters. |
| 5 | 5 |
| 6 | 6 |
| 7 class TypeTester<T> {} | 7 class TypeTester<T> {} |
| 8 | 8 |
| 9 // Expect compile-time error as no default values are allowed | 9 // Expect compile-time error as no default values are allowed |
| 10 // in closure type definitions. | 10 // in closure type definitions. |
| 11 typedef void Callback([String msg | 11 typedef void Callback([String msg |
| 12 = "" /// 01: compile-time error | 12 = "" /// 01: compile-time error |
| 13 ]); | 13 ]); |
| 14 | 14 |
| 15 class NamedParametersAggregatedTests { | 15 class NamedParametersAggregatedTests { |
| 16 | 16 |
| 17 static int F31(int a, [int b = 20, int c = 30]) { | 17 static int F31(int a, {int b: 20, int c: 30}) { |
| 18 return 100*(100*a + b) + c; | 18 return 100*(100*a + b) + c; |
| 19 } | 19 } |
| 20 | 20 |
| 21 static int f_missing_comma(a | 21 static int f_missing_comma(a |
| 22 [b = 42] /// 02: compile-time error | 22 [b = 42] /// 02: compile-time error |
| 23 ) => a; | 23 ) => a; |
| 24 | 24 |
| 25 var _handler = null; | 25 var _handler = null; |
| 26 | 26 |
| 27 // Expect compile-time error as no default values | 27 // Expect compile-time error as no default values |
| 28 // are allowed in closure type. | 28 // are allowed in closure type. |
| 29 void InstallCallback(void cb([String msg | 29 void InstallCallback(void cb({String msg |
| 30 = null /// 03: compile-time error | 30 : null /// 03: compile-time error |
| 31 ])) { | 31 })) { |
| 32 _handler = cb; | 32 _handler = cb; |
| 33 } | 33 } |
| 34 | 34 |
| 35 } | 35 } |
| 36 | 36 |
| 37 | 37 |
| 38 main() { | 38 main() { |
| 39 // Expect compile-time error due to missing comma in function definition. | 39 // Expect compile-time error due to missing comma in function definition. |
| 40 NamedParametersAggregatedTests.f_missing_comma(10 | 40 NamedParametersAggregatedTests.f_missing_comma(10 |
| 41 , 25 /// 02: continued | 41 , 25 /// 02: continued |
| 42 ); | 42 ); |
| 43 | 43 |
| 44 // Expect compile-time erorr due to duplicate named argument. | 44 // Expect compile-time erorr due to duplicate named argument. |
| 45 NamedParametersAggregatedTests.F31(10, b:25 | 45 NamedParametersAggregatedTests.F31(10, b:25 |
| 46 , b:35 /// 04: compile-time error | 46 , b:35 /// 04: compile-time error |
| 47 ); | 47 ); |
| 48 | 48 |
| 49 // Expect compile-time error due to missing positional argument. | 49 // Expect compile-time error due to missing positional argument. |
| 50 NamedParametersAggregatedTests.F31(b:25, c:35); /// 05: static type warning | 50 NamedParametersAggregatedTests.F31(b:25, c:35); /// 05: static type warning |
| 51 | 51 |
| 52 new TypeTester<Callback>(); | 52 new TypeTester<Callback>(); |
| 53 | 53 |
| 54 (new NamedParametersAggregatedTests()).InstallCallback(null); | 54 (new NamedParametersAggregatedTests()).InstallCallback(null); |
| 55 | 55 |
| 56 } | 56 } |
| OLD | NEW |