OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2017, 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 that generic methods with unused parameters aren't treated as |
| 6 // non-generic methods, but can be specialized as such. |
| 7 |
| 8 library generic_methods_unused_parameter_test; |
| 9 |
| 10 import "test_base.dart"; |
| 11 |
| 12 typedef Fun = int Function(); |
| 13 typedef FunReq = int Function(int); |
| 14 typedef FunOpt = int Function([int]); |
| 15 typedef FunReqOpt = int Function(int, [int]); |
| 16 typedef FunNam = int Function({int p}); |
| 17 typedef FunReqNam = int Function(int, {int p}); |
| 18 |
| 19 typedef FunTyp = int Function<T>(); |
| 20 typedef FunTypReq = int Function<T>(int); |
| 21 typedef FunTypOpt = int Function<T>([int]); |
| 22 typedef FunTypReqOpt = int Function<T>(int, [int]); |
| 23 typedef FunTypNam = int Function<T>({int p}); |
| 24 typedef FunTypReqNam = int Function<T>(int, {int p}); |
| 25 |
| 26 int fun() {} |
| 27 int funReq(int x) => x; |
| 28 int funOpt([int y]) => y ?? 42; |
| 29 int funReqOpt(int x, [int y]) => x; |
| 30 int funNam({int p}) => p ?? 42; |
| 31 int funReqNam(int x, {int p}) => x; |
| 32 |
| 33 int funTyp<T>() {} |
| 34 int funTypReq<T>(int x) => x; |
| 35 int funTypOpt<T>([int y]) => y ?? 42; |
| 36 int funTypReqOpt<T>(int x, [int y]) => x; |
| 37 int funTypNam<T>({int p}) => p ?? 42; |
| 38 int funTypReqNam<T>(int x, {int p}) => x; |
| 39 |
| 40 main() { |
| 41 Fun varFun = funTyp; |
| 42 FunReq varFunReq = funTypReq; |
| 43 FunOpt varFunOpt = funTypOpt; |
| 44 FunReqOpt varFunReqOpt = funTypReqOpt; |
| 45 FunNam varFunNam = funTypNam; |
| 46 FunReqNam varFunReqNam = funTypReqNam; |
| 47 |
| 48 expectTrue(fun is Fun); |
| 49 expectTrue(fun is! FunTyp); |
| 50 expectTrue(funTyp is! Fun); |
| 51 expectTrue(funTyp is FunTyp); |
| 52 expectTrue(varFun is Fun); |
| 53 expectTrue(varFun is! FunTyp); |
| 54 |
| 55 expectTrue(funReq is FunReq); |
| 56 expectTrue(funReq is! FunTypReq); |
| 57 expectTrue(funTypReq is! FunReq); |
| 58 expectTrue(funTypReq is FunTypReq); |
| 59 expectTrue(varFunReq is FunReq); |
| 60 expectTrue(varFunReq is! FunTypReq); |
| 61 |
| 62 expectTrue(funOpt is FunOpt); |
| 63 expectTrue(funOpt is! FunTypOpt); |
| 64 expectTrue(funTypOpt is! FunOpt); |
| 65 expectTrue(funTypOpt is FunTypOpt); |
| 66 expectTrue(varFunOpt is FunOpt); |
| 67 expectTrue(varFunOpt is! FunTypOpt); |
| 68 |
| 69 expectTrue(funReqOpt is FunReqOpt); |
| 70 expectTrue(funReqOpt is! FunTypReqOpt); |
| 71 expectTrue(funTypReqOpt is! FunReqOpt); |
| 72 expectTrue(funTypReqOpt is FunTypReqOpt); |
| 73 expectTrue(varFunReqOpt is FunReqOpt); |
| 74 expectTrue(varFunReqOpt is! FunTypReqOpt); |
| 75 |
| 76 expectTrue(funNam is FunNam); |
| 77 expectTrue(funNam is! FunTypNam); |
| 78 expectTrue(funTypNam is! FunNam); |
| 79 expectTrue(funTypNam is FunTypNam); |
| 80 expectTrue(varFunNam is FunNam); |
| 81 expectTrue(varFunNam is! FunTypNam); |
| 82 |
| 83 expectTrue(funReqNam is FunReqNam); |
| 84 expectTrue(funReqNam is! FunTypReqNam); |
| 85 expectTrue(funTypReqNam is! FunReqNam); |
| 86 expectTrue(funTypReqNam is FunTypReqNam); |
| 87 expectTrue(varFunReqNam is FunReqNam); |
| 88 expectTrue(varFunReqNam is! FunTypReqNam); |
| 89 } |
OLD | NEW |