From 1efb5174f26caeebafe1b5ea9487690c5ffe1adb Mon Sep 17 00:00:00 2001 From: Araq Date: Mon, 9 Mar 2015 15:02:28 +0100 Subject: fixes #2220; #2219; breaks #2022; for #2022 callsite needs to be used --- tests/overload/toverprc.nim | 30 +++++++++++------- tests/overload/tprefer_specialized_generic.nim | 22 +++++++++++++ tests/overload/tprefer_tygenericinst.nim | 43 ++++++++++++++++++++------ tests/overload/tsystemcmp.nim | 9 ++++++ 4 files changed, 83 insertions(+), 21 deletions(-) create mode 100644 tests/overload/tprefer_specialized_generic.nim (limited to 'tests/overload') diff --git a/tests/overload/toverprc.nim b/tests/overload/toverprc.nim index 22b64ed48..78831f744 100644 --- a/tests/overload/toverprc.nim +++ b/tests/overload/toverprc.nim @@ -1,14 +1,19 @@ +discard """ + output: '''another number: 123 +yay''' +""" + # Test overloading of procs when used as function pointers import strutils -proc parseInt(x: float): int {.noSideEffect.} = nil -proc parseInt(x: bool): int {.noSideEffect.} = nil -proc parseInt(x: float32): int {.noSideEffect.} = nil -proc parseInt(x: int8): int {.noSideEffect.} = nil -proc parseInt(x: TFile): int {.noSideEffect.} = nil -proc parseInt(x: char): int {.noSideEffect.} = nil -proc parseInt(x: int16): int {.noSideEffect.} = nil +proc parseInt(x: float): int {.noSideEffect.} = discard +proc parseInt(x: bool): int {.noSideEffect.} = discard +proc parseInt(x: float32): int {.noSideEffect.} = discard +proc parseInt(x: int8): int {.noSideEffect.} = discard +proc parseInt(x: TFile): int {.noSideEffect.} = discard +proc parseInt(x: char): int {.noSideEffect.} = discard +proc parseInt(x: int16): int {.noSideEffect.} = discard proc parseInt[T](x: T): int = echo x; 34 @@ -19,12 +24,13 @@ var q = TParseInt(parseInt) p: TParseInt = parseInt -proc takeParseInt(x: proc (y: string): int {.noSideEffect.}): int = +proc takeParseInt(x: proc (y: string): int {.noSideEffect.}): int = result = x("123") - -echo "Give a list of numbers (separated by spaces): " -var x = stdin.readline.split.map(parseInt).max -echo x, " is the maximum!" + +if false: + echo "Give a list of numbers (separated by spaces): " + var x = stdin.readline.split.map(parseInt).max + echo x, " is the maximum!" echo "another number: ", takeParseInt(parseInt) diff --git a/tests/overload/tprefer_specialized_generic.nim b/tests/overload/tprefer_specialized_generic.nim new file mode 100644 index 000000000..2b41502d1 --- /dev/null +++ b/tests/overload/tprefer_specialized_generic.nim @@ -0,0 +1,22 @@ +discard """ + output: '''ref ref T ptr S''' +""" + +proc foo[T](x: T) = + echo "only T" + +proc foo[T](x: ref T) = + echo "ref T" + +proc foo[T, S](x: ref ref T; y: ptr S) = + echo "ref ref T ptr S" + +proc foo[T, S](x: ref T; y: ptr S) = + echo "ref T ptr S" + +proc foo[T](x: ref T; default = 0) = + echo "ref T; default" + +var x: ref ref int +var y: ptr ptr int +foo(x, y) diff --git a/tests/overload/tprefer_tygenericinst.nim b/tests/overload/tprefer_tygenericinst.nim index 2700bed5e..9787af06b 100644 --- a/tests/overload/tprefer_tygenericinst.nim +++ b/tests/overload/tprefer_tygenericinst.nim @@ -1,17 +1,42 @@ discard """ - output: "Version 2 was called." - disabled: true + output: '''Version 2 was called. +This has the highest precedence. +This has the second-highest precedence. +This has the lowest precedence.''' """ # bug #2220 +when true: + type A[T] = object + type B = A[int] -type A[T] = object -type B = A[int] + proc q[X](x: X) = + echo "Version 1 was called." -proc p[X](x: X) = - echo "Version 1 was called." + proc q(x: B) = + echo "Version 2 was called." -proc p(x: B) = - echo "Version 2 was called." + q(B()) # This call reported as ambiguous. -p(B()) # This call reported as ambiguous. +# bug #2219 +template testPred(a: expr) = + block: + type A = object of RootObj + type B = object of A + type SomeA = A|A # A hack to make "A" a typeclass. + + when a >= 3: + proc p[X](x: X) = + echo "This has the highest precedence." + when a >= 2: + proc p[X: A](x: X) = + echo "This has the second-highest precedence." + when a >= 1: + proc p[X: SomeA](x: X) = + echo "This has the lowest precedence." + + p(B()) + +testPred(3) +testPred(2) +testPred(1) diff --git a/tests/overload/tsystemcmp.nim b/tests/overload/tsystemcmp.nim index 54dff0c46..9bfca35d7 100644 --- a/tests/overload/tsystemcmp.nim +++ b/tests/overload/tsystemcmp.nim @@ -7,3 +7,12 @@ import algorithm # bug #1657 var modules = @["hi", "ho", "ha", "huu"] sort(modules, system.cmp) + +type + MyType = object + x: string + +proc cmp(a, b: MyType): int = cmp(a.x, b.x) + +var modulesB = @[MyType(x: "ho"), MyType(x: "ha")] +sort(modulesB, cmp) -- cgit 1.4.1-2-gfad0 a id='n61' href='#n61'>61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387