| 1 |
// PERMUTE_ARGS: |
| 2 |
|
| 3 |
extern(C) int printf(const char*, ...); |
| 4 |
|
| 5 |
/*******************************************************/ |
| 6 |
|
| 7 |
interface Foo { int bar(); } |
| 8 |
|
| 9 |
void* p1; |
| 10 |
|
| 11 |
class Bar : Foo |
| 12 |
{ |
| 13 |
int bar() |
| 14 |
{ |
| 15 |
printf("Bar.bar(this = %p)\n", this); |
| 16 |
p1 = cast(void*)this; |
| 17 |
return 0; |
| 18 |
} |
| 19 |
} |
| 20 |
|
| 21 |
void test1() |
| 22 |
{ |
| 23 |
Bar b = new Bar(); |
| 24 |
Foo f = b; |
| 25 |
|
| 26 |
printf("b = %p\n", b); |
| 27 |
printf("f = %p\n", f); |
| 28 |
assert(cast(void*)b !is cast(void*)f); |
| 29 |
|
| 30 |
printf("f.class = '%.*s'\n", cast(int)f.classinfo.name.length, f.classinfo.name.ptr); |
| 31 |
assert(f.classinfo.name == "interface2.Foo"); |
| 32 |
|
| 33 |
f.bar(); |
| 34 |
assert(p1 is cast(void*)b); |
| 35 |
|
| 36 |
Bar b2 = cast(Bar)f; |
| 37 |
printf("cast(Bar)f = %p\n", b2); |
| 38 |
assert(b is b2); |
| 39 |
|
| 40 |
destroy(f); |
| 41 |
} |
| 42 |
|
| 43 |
/*******************************************************/ |
| 44 |
|
| 45 |
interface A {} |
| 46 |
interface B:A {} |
| 47 |
interface C {} |
| 48 |
class D:B,C {} |
| 49 |
|
| 50 |
void test2() |
| 51 |
{ |
| 52 |
D x = new D(); |
| 53 |
printf("D: %p\n",x); |
| 54 |
Object o = x; |
| 55 |
printf("o: %p\n",o); |
| 56 |
B b = cast(B)o; |
| 57 |
printf("B: %p\n",b); |
| 58 |
C c = cast(C)o; // boom |
| 59 |
printf("C: %p\n",c); |
| 60 |
} |
| 61 |
|
| 62 |
/*******************************************************/ |
| 63 |
|
| 64 |
interface B3 |
| 65 |
{ |
| 66 |
void close(); |
| 67 |
} |
| 68 |
|
| 69 |
interface C3 : B3 |
| 70 |
{ |
| 71 |
} |
| 72 |
|
| 73 |
class A3 : B3 |
| 74 |
{ |
| 75 |
void close() |
| 76 |
{ |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
class D3 : A3 |
| 81 |
{ |
| 82 |
} |
| 83 |
|
| 84 |
class E3 : D3, C3 |
| 85 |
{ |
| 86 |
} |
| 87 |
|
| 88 |
void test3() |
| 89 |
{ |
| 90 |
C3 c = new E3(); |
| 91 |
destroy(c); |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
/*******************************************************/ |
| 96 |
|
| 97 |
interface K |
| 98 |
{ |
| 99 |
} |
| 100 |
|
| 101 |
interface X |
| 102 |
{ |
| 103 |
} |
| 104 |
|
| 105 |
interface Y : X |
| 106 |
{ |
| 107 |
} |
| 108 |
|
| 109 |
class Z : Y |
| 110 |
{ |
| 111 |
} |
| 112 |
|
| 113 |
void test4() |
| 114 |
{ |
| 115 |
Z z = new Z(); |
| 116 |
if (cast(K) z) |
| 117 |
{ |
| 118 |
printf("not ok\n"); |
| 119 |
assert(0); |
| 120 |
} |
| 121 |
} |
| 122 |
|
| 123 |
/*******************************************************/ |
| 124 |
|
| 125 |
interface I5 |
| 126 |
{ |
| 127 |
char M (); |
| 128 |
} |
| 129 |
|
| 130 |
interface J5 : I5 |
| 131 |
{ |
| 132 |
char N (); |
| 133 |
} |
| 134 |
|
| 135 |
class A5 : I5 |
| 136 |
{ |
| 137 |
char M () { printf("M()\n"); return 'M'; } |
| 138 |
} |
| 139 |
|
| 140 |
class B5 : A5, J5 |
| 141 |
{ |
| 142 |
char N () { printf("N()\n"); return 'N'; } |
| 143 |
} |
| 144 |
|
| 145 |
void test5() |
| 146 |
{ |
| 147 |
I5 f = new B5 (); |
| 148 |
|
| 149 |
char c = f.M(); |
| 150 |
assert(c == 'M'); |
| 151 |
} |
| 152 |
|
| 153 |
/*******************************************************/ |
| 154 |
|
| 155 |
interface A6 |
| 156 |
{ |
| 157 |
void ma (); |
| 158 |
} |
| 159 |
|
| 160 |
interface B6 |
| 161 |
{ |
| 162 |
void mb (); |
| 163 |
} |
| 164 |
|
| 165 |
class C6 : A6, B6 |
| 166 |
{ |
| 167 |
void ma () { } |
| 168 |
void mb () { } |
| 169 |
} |
| 170 |
|
| 171 |
void test6() |
| 172 |
{ |
| 173 |
A6 x = new C6 (); |
| 174 |
|
| 175 |
assert (cast (B6) x); |
| 176 |
} |
| 177 |
|
| 178 |
/*******************************************************/ |
| 179 |
|
| 180 |
interface D7 { int foo(); } |
| 181 |
|
| 182 |
class A7 : D7 { int foo() { return 1; } } |
| 183 |
|
| 184 |
class B7 : A7 |
| 185 |
{ |
| 186 |
override int foo() { return 2; } |
| 187 |
D7 me() { return this; } |
| 188 |
} |
| 189 |
|
| 190 |
void test7() |
| 191 |
{ |
| 192 |
A7 a = new A7; |
| 193 |
B7 b = new B7; |
| 194 |
assert(b.me().foo() != a.foo()); |
| 195 |
} |
| 196 |
|
| 197 |
/*******************************************************/ |
| 198 |
|
| 199 |
interface D8 { void foo(); } |
| 200 |
|
| 201 |
class A8 : D8 { void foo() { printf("A8.foo()\n"); } } |
| 202 |
|
| 203 |
class B8 : A8 {} |
| 204 |
|
| 205 |
void test8() |
| 206 |
{ |
| 207 |
B8 b = new B8(); |
| 208 |
D8 d = cast(D8) b; |
| 209 |
d.foo(); |
| 210 |
} |
| 211 |
|
| 212 |
/*******************************************************/ |
| 213 |
|
| 214 |
interface IA9 |
| 215 |
{ |
| 216 |
int i1(); |
| 217 |
} |
| 218 |
|
| 219 |
interface IB9 |
| 220 |
{ |
| 221 |
int i2(); |
| 222 |
} |
| 223 |
|
| 224 |
interface IC9 : IA9, IB9 |
| 225 |
{ |
| 226 |
} |
| 227 |
|
| 228 |
class C9 : IC9 |
| 229 |
{ |
| 230 |
int i1() { printf("i1\n"); return 1; } |
| 231 |
int i2() { printf("i2\n"); return 2; } |
| 232 |
} |
| 233 |
|
| 234 |
void f9(IA9 i1, IB9 i2) |
| 235 |
{ |
| 236 |
int i; |
| 237 |
|
| 238 |
printf("f9\n"); |
| 239 |
i = i1.i1(); |
| 240 |
assert(i == 1); |
| 241 |
i = i2.i2(); |
| 242 |
assert(i == 2); |
| 243 |
} |
| 244 |
|
| 245 |
void test9() |
| 246 |
{ |
| 247 |
IC9 i3 = new C9(); |
| 248 |
C9 c = new C9(); |
| 249 |
f9(c, c); |
| 250 |
//printf("c = %p, IC9 = %p, IA9 = %p, IB9 = %p\n", c, i3, cast(IA9)i3, cast(IB9)i3); |
| 251 |
f9(i3, i3); |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
/*******************************************************/ |
| 256 |
|
| 257 |
interface IOne |
| 258 |
{ |
| 259 |
int one (); |
| 260 |
} |
| 261 |
|
| 262 |
interface ITwo |
| 263 |
{ |
| 264 |
int two (); |
| 265 |
} |
| 266 |
|
| 267 |
interface IThree : IOne, ITwo |
| 268 |
{ |
| 269 |
int three (); |
| 270 |
} |
| 271 |
|
| 272 |
class Three : IThree |
| 273 |
{ |
| 274 |
int one () { printf ("one\n"); return 1; } |
| 275 |
int two () { printf ("two\n"); return 2; } |
| 276 |
int three () { printf ("three\n"); return 3; } |
| 277 |
} |
| 278 |
|
| 279 |
|
| 280 |
void test10() |
| 281 |
{ |
| 282 |
int i; |
| 283 |
IThree three = new Three; |
| 284 |
|
| 285 |
i = three.one(); |
| 286 |
assert(i == 1); |
| 287 |
i = three.two(); |
| 288 |
assert(i == 2); |
| 289 |
i = three.three(); |
| 290 |
assert(i == 3); |
| 291 |
|
| 292 |
ITwo two = cast(ITwo) three; |
| 293 |
i = two.two(); |
| 294 |
assert(i == 2); |
| 295 |
} |
| 296 |
|
| 297 |
|
| 298 |
/*******************************************************/ |
| 299 |
|
| 300 |
interface A11{ |
| 301 |
} |
| 302 |
|
| 303 |
interface B11 : A11{ |
| 304 |
} |
| 305 |
|
| 306 |
class MyClass : B11{ |
| 307 |
} |
| 308 |
|
| 309 |
void test11() |
| 310 |
{ |
| 311 |
B11 b = new MyClass(); |
| 312 |
Object o = cast(Object)b; |
| 313 |
printf("o = %p\n", o); |
| 314 |
} |
| 315 |
|
| 316 |
/*******************************************************/ |
| 317 |
|
| 318 |
interface I12 |
| 319 |
{ |
| 320 |
int foo(); |
| 321 |
} |
| 322 |
|
| 323 |
class IA12 : I12 |
| 324 |
{ |
| 325 |
int foo() { return 1; } |
| 326 |
} |
| 327 |
|
| 328 |
class A12 |
| 329 |
{ |
| 330 |
I12 i; |
| 331 |
|
| 332 |
I12 clone() { return i; } |
| 333 |
} |
| 334 |
|
| 335 |
class B12 : A12 |
| 336 |
{ |
| 337 |
IA12 ia; |
| 338 |
|
| 339 |
override IA12 clone() // covariant return value |
| 340 |
out (result) |
| 341 |
{ |
| 342 |
printf("B12.clone()\n"); |
| 343 |
} |
| 344 |
do |
| 345 |
{ |
| 346 |
return ia; |
| 347 |
} |
| 348 |
} |
| 349 |
|
| 350 |
void test12() |
| 351 |
{ |
| 352 |
IA12 ia = new IA12; |
| 353 |
assert(ia.foo() == 1); |
| 354 |
|
| 355 |
I12 i = ia; |
| 356 |
assert(i.foo() == 1); |
| 357 |
|
| 358 |
A12 a = new A12; |
| 359 |
a.i = i; |
| 360 |
assert(a.clone().foo() == 1); |
| 361 |
|
| 362 |
B12 b = new B12; |
| 363 |
b.ia = ia; |
| 364 |
assert(b.clone().foo() == 1); |
| 365 |
|
| 366 |
a = b; |
| 367 |
assert(a.clone().foo() == 1); |
| 368 |
} |
| 369 |
|
| 370 |
/*******************************************************/ |
| 371 |
|
| 372 |
class I13 |
| 373 |
{ |
| 374 |
int foo() { return 0; } |
| 375 |
} |
| 376 |
|
| 377 |
class IA13 : I13 |
| 378 |
{ |
| 379 |
override int foo() { return 1; } |
| 380 |
} |
| 381 |
|
| 382 |
class A13 |
| 383 |
{ |
| 384 |
I13 i; |
| 385 |
|
| 386 |
I13 clone() { return i; } |
| 387 |
} |
| 388 |
|
| 389 |
class B13 : A13 |
| 390 |
{ |
| 391 |
IA13 ia; |
| 392 |
|
| 393 |
override IA13 clone() |
| 394 |
out (result) |
| 395 |
{ |
| 396 |
printf("B13.clone()\n"); |
| 397 |
} |
| 398 |
do { return ia; } |
| 399 |
} |
| 400 |
|
| 401 |
void test13() |
| 402 |
{ |
| 403 |
IA13 ia = new IA13; |
| 404 |
assert(ia.foo() == 1); |
| 405 |
|
| 406 |
I13 i = ia; |
| 407 |
assert(i.foo() == 1); |
| 408 |
|
| 409 |
A13 a = new A13; |
| 410 |
a.i = i; |
| 411 |
assert(a.clone().foo() == 1); |
| 412 |
|
| 413 |
B13 b = new B13; |
| 414 |
b.ia = ia; |
| 415 |
assert(b.clone().foo() == 1); |
| 416 |
|
| 417 |
a = b; |
| 418 |
assert(a.clone().foo() == 1); |
| 419 |
|
| 420 |
bar(&b.clone); |
| 421 |
} |
| 422 |
|
| 423 |
void bar(IA13 delegate() dg) |
| 424 |
{ |
| 425 |
} |
| 426 |
|
| 427 |
/*******************************************************/ |
| 428 |
|
| 429 |
interface I14 |
| 430 |
{ |
| 431 |
I14 clone(); |
| 432 |
} |
| 433 |
|
| 434 |
interface BabyI14: I14 |
| 435 |
{ |
| 436 |
} |
| 437 |
|
| 438 |
class A14: BabyI14 |
| 439 |
{ |
| 440 |
int x; |
| 441 |
BabyI14 clone() |
| 442 |
{ |
| 443 |
A14 a = new A14; |
| 444 |
a.x = x; |
| 445 |
return a; |
| 446 |
} |
| 447 |
} |
| 448 |
|
| 449 |
I14 foo14(I14 i) |
| 450 |
{ |
| 451 |
return i.clone(); |
| 452 |
} |
| 453 |
|
| 454 |
void test14() |
| 455 |
{ |
| 456 |
A14 a = new A14; |
| 457 |
a.x = 3; |
| 458 |
a = cast(A14)a.clone(); |
| 459 |
assert(a.x == 3); |
| 460 |
|
| 461 |
A14 b = cast(A14)foo14(a); |
| 462 |
a.x = 4; |
| 463 |
assert(b.x == 3); |
| 464 |
} |
| 465 |
|
| 466 |
/*******************************************************/ |
| 467 |
|
| 468 |
interface I15 |
| 469 |
{ |
| 470 |
Object clone(); |
| 471 |
} |
| 472 |
|
| 473 |
class A15 : I15 |
| 474 |
{ |
| 475 |
int x; |
| 476 |
A15 clone() { return this; } |
| 477 |
} |
| 478 |
|
| 479 |
void test15() |
| 480 |
{ |
| 481 |
A15 a = new A15; |
| 482 |
a.x = 3; |
| 483 |
|
| 484 |
A15 a1 = a.clone(); |
| 485 |
assert(a1.x == 3); |
| 486 |
|
| 487 |
I15 i = a1; |
| 488 |
Object o = i.clone(); |
| 489 |
A15 a2 = cast(A15) o; |
| 490 |
assert(a2.x == 3); |
| 491 |
} |
| 492 |
|
| 493 |
/*******************************************************/ |
| 494 |
|
| 495 |
interface I16 {} |
| 496 |
|
| 497 |
class A16 |
| 498 |
{ |
| 499 |
I16 foo() |
| 500 |
{ |
| 501 |
printf("Called A.foo\n"); |
| 502 |
return new B16(42); |
| 503 |
} |
| 504 |
} |
| 505 |
|
| 506 |
class B16 : A16, I16 |
| 507 |
{ |
| 508 |
int data; |
| 509 |
|
| 510 |
this(int d) { data = d; } |
| 511 |
|
| 512 |
override B16 foo() |
| 513 |
{ |
| 514 |
printf("Called B.foo\n"); |
| 515 |
return new B16(69); |
| 516 |
} |
| 517 |
} |
| 518 |
|
| 519 |
void test16() |
| 520 |
{ |
| 521 |
B16 b = new B16(105); |
| 522 |
b.foo(); |
| 523 |
A16 a = b; |
| 524 |
a.foo(); |
| 525 |
printf("foo\n"); |
| 526 |
B16 b2 = cast(B16) a.foo(); |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
/*******************************************************/ |
| 531 |
|
| 532 |
interface Father |
| 533 |
{ |
| 534 |
int showData(); |
| 535 |
} |
| 536 |
|
| 537 |
class Mother |
| 538 |
{ |
| 539 |
Father test() { |
| 540 |
printf("Called Mother.test\n"); |
| 541 |
return new Child(42); |
| 542 |
} |
| 543 |
} |
| 544 |
|
| 545 |
class Child : Mother, Father { |
| 546 |
int data; |
| 547 |
|
| 548 |
this(int d) { data = d; } |
| 549 |
|
| 550 |
override Child test() |
| 551 |
{ |
| 552 |
printf("Called Child.test\n"); |
| 553 |
return new Child(69); |
| 554 |
} |
| 555 |
|
| 556 |
int showData() { |
| 557 |
printf("%d\n", data); |
| 558 |
return data; |
| 559 |
} |
| 560 |
} |
| 561 |
|
| 562 |
void test17() |
| 563 |
{ |
| 564 |
Child aChild = new Child(105); |
| 565 |
Mother childsMum = aChild; |
| 566 |
|
| 567 |
aChild.test(); |
| 568 |
Father mumTest = childsMum.test(); |
| 569 |
int i; |
| 570 |
i = aChild.showData(); |
| 571 |
assert(i == 105); |
| 572 |
i = mumTest.showData(); |
| 573 |
assert(i == 69); |
| 574 |
} |
| 575 |
|
| 576 |
|
| 577 |
/*******************************************************/ |
| 578 |
|
| 579 |
int status18; |
| 580 |
|
| 581 |
interface I18 { |
| 582 |
int showData(); |
| 583 |
} |
| 584 |
|
| 585 |
class Parent18 { |
| 586 |
I18 test() { |
| 587 |
status18 += 7; |
| 588 |
return new Child18(42); |
| 589 |
} |
| 590 |
} |
| 591 |
|
| 592 |
class Child18 : Parent18, I18 { |
| 593 |
int data; |
| 594 |
|
| 595 |
this(int d) { |
| 596 |
data = d; |
| 597 |
} |
| 598 |
|
| 599 |
override Child18 test() { |
| 600 |
status18 += 1; |
| 601 |
return new Child18(69); |
| 602 |
} |
| 603 |
|
| 604 |
override |
| 605 |
int showData(){ |
| 606 |
return data; |
| 607 |
} |
| 608 |
} |
| 609 |
|
| 610 |
void test18() |
| 611 |
{ |
| 612 |
Child18 a = new Child18(105); |
| 613 |
assert(a); |
| 614 |
assert(status18 == 0); |
| 615 |
assert(a.data == 105); |
| 616 |
|
| 617 |
Parent18 p = a; |
| 618 |
assert(a); |
| 619 |
assert(status18 == 0); |
| 620 |
|
| 621 |
a.test(); |
| 622 |
assert(status18 == 1); |
| 623 |
|
| 624 |
I18 i = p.test(); |
| 625 |
assert(i); |
| 626 |
assert(status18 == 2); |
| 627 |
|
| 628 |
assert(a.data == 105); |
| 629 |
assert(a.showData() == 105); |
| 630 |
assert(i.showData() == 69); |
| 631 |
} |
| 632 |
|
| 633 |
/*******************************************************/ |
| 634 |
|
| 635 |
|
| 636 |
interface IFoo19 { |
| 637 |
} |
| 638 |
|
| 639 |
interface ICov19 { |
| 640 |
IFoo19 covfunc(); |
| 641 |
} |
| 642 |
|
| 643 |
class Child19 : ICov19, IFoo19 { |
| 644 |
Child19 covfunc() { |
| 645 |
printf("in Child19.covfunc()\n"); |
| 646 |
return this; |
| 647 |
} |
| 648 |
} |
| 649 |
|
| 650 |
void test19() |
| 651 |
{ |
| 652 |
Child19 c = new Child19(); |
| 653 |
ICov19 icov = c; |
| 654 |
|
| 655 |
IFoo19 ifoo = icov.covfunc(); |
| 656 |
|
| 657 |
printf("c = %p\n", c); |
| 658 |
printf("icov = %p\n", icov); |
| 659 |
printf("ifoo = %p\n", ifoo); |
| 660 |
|
| 661 |
assert(cast(void*)c + (2*(void*).sizeof) == cast(void*)icov); |
| 662 |
assert(cast(void*)c + (3*(void*).sizeof) == cast(void*)ifoo); |
| 663 |
|
| 664 |
string s = ifoo.classinfo.name; |
| 665 |
printf("%.*s\n", cast(int)s.length, s.ptr); |
| 666 |
assert(s == "interface2.IFoo19"); |
| 667 |
|
| 668 |
s = (cast(Object)ifoo).toString; |
| 669 |
printf("%.*s\n", cast(int)s.length, s.ptr); |
| 670 |
assert(s == "interface2.Child19"); |
| 671 |
} |
| 672 |
|
| 673 |
/*******************************************************/ |
| 674 |
|
| 675 |
interface Iface1 |
| 676 |
{ |
| 677 |
Iface2 func1(); |
| 678 |
} |
| 679 |
|
| 680 |
interface Iface2 |
| 681 |
{ |
| 682 |
Iface1 func2(); |
| 683 |
} |
| 684 |
|
| 685 |
class C1_20 : Iface1 |
| 686 |
{ |
| 687 |
C2_20 func1(){ return null; } |
| 688 |
} |
| 689 |
|
| 690 |
class C2_20 : Iface2 |
| 691 |
{ |
| 692 |
C1_20 func2(){ return null; } |
| 693 |
} |
| 694 |
|
| 695 |
void test20() |
| 696 |
{ |
| 697 |
C1_20 c1 = new C1_20(); |
| 698 |
printf("c1.func1() == %p\n", c1.func1()); |
| 699 |
assert(c1.func1() is null); |
| 700 |
printf("test1\n"); |
| 701 |
|
| 702 |
C2_20 c2 = new C2_20(); |
| 703 |
printf("c2.func2() == %p\n", c2.func2()); |
| 704 |
assert(c2.func2() is null); |
| 705 |
} |
| 706 |
|
| 707 |
/*******************************************************/ |
| 708 |
|
| 709 |
interface I21 |
| 710 |
{ |
| 711 |
int test(int); |
| 712 |
} |
| 713 |
|
| 714 |
class C21 : I21 |
| 715 |
{ |
| 716 |
int test(int i){ |
| 717 |
return i+1; |
| 718 |
} |
| 719 |
} |
| 720 |
|
| 721 |
void test21() |
| 722 |
{ |
| 723 |
C21[I21] aa; |
| 724 |
|
| 725 |
C21 o = new C21(); |
| 726 |
|
| 727 |
aa[o] = o; |
| 728 |
|
| 729 |
I21 i = aa[o]; |
| 730 |
assert(i.test(3) == 4); |
| 731 |
} |
| 732 |
|
| 733 |
|
| 734 |
/*******************************************************/ |
| 735 |
|
| 736 |
interface IFoo22 |
| 737 |
{ |
| 738 |
int foo(); |
| 739 |
} |
| 740 |
|
| 741 |
class Foo22: IFoo22 |
| 742 |
{ |
| 743 |
final int foo() { return 7; } |
| 744 |
} |
| 745 |
|
| 746 |
void test22() |
| 747 |
{ |
| 748 |
Foo22 f = new Foo22; |
| 749 |
assert(f.foo() == 7); |
| 750 |
|
| 751 |
IFoo22 i = f; |
| 752 |
assert(i.foo() == 7); |
| 753 |
} |
| 754 |
|
| 755 |
/*******************************************************/ |
| 756 |
|
| 757 |
interface IFoo23 |
| 758 |
{ |
| 759 |
int foo(); |
| 760 |
} |
| 761 |
|
| 762 |
class Foo23: IFoo23 |
| 763 |
{ |
| 764 |
final int foo() { return 7; } |
| 765 |
} |
| 766 |
|
| 767 |
class Baz23 : Foo23 |
| 768 |
{ |
| 769 |
} |
| 770 |
|
| 771 |
void test23() |
| 772 |
{ |
| 773 |
Baz23 f = new Baz23; |
| 774 |
assert(f.foo() == 7); |
| 775 |
|
| 776 |
IFoo23 i = f; |
| 777 |
assert(i.foo() == 7); |
| 778 |
} |
| 779 |
|
| 780 |
/*******************************************************/ |
| 781 |
|
| 782 |
interface I24B() : I24A |
| 783 |
{ |
| 784 |
} |
| 785 |
|
| 786 |
interface I24A |
| 787 |
{ |
| 788 |
I24B!() func (); |
| 789 |
} |
| 790 |
|
| 791 |
class Foo24 : I24B!() |
| 792 |
{ |
| 793 |
I24B!() func() |
| 794 |
{ |
| 795 |
return null; |
| 796 |
} |
| 797 |
} |
| 798 |
|
| 799 |
void test24() |
| 800 |
{ |
| 801 |
auto foo = new Foo24(); |
| 802 |
|
| 803 |
foo.func(); |
| 804 |
printf("foo.func() call passed\n"); |
| 805 |
|
| 806 |
I24A ifA = foo; |
| 807 |
assert(ifA !is null); |
| 808 |
ifA.func(); |
| 809 |
} |
| 810 |
|
| 811 |
/*******************************************************/ |
| 812 |
|
| 813 |
interface IA25 |
| 814 |
{ |
| 815 |
char a(); |
| 816 |
} |
| 817 |
|
| 818 |
interface IB25 |
| 819 |
{ |
| 820 |
char b(); |
| 821 |
} |
| 822 |
|
| 823 |
interface IC25 : IA25, IB25 |
| 824 |
{ |
| 825 |
char c(); |
| 826 |
} |
| 827 |
|
| 828 |
interface ID25 |
| 829 |
{ |
| 830 |
char d(); |
| 831 |
} |
| 832 |
|
| 833 |
interface IE25 : IC25, ID25 |
| 834 |
{ |
| 835 |
char e(); |
| 836 |
} |
| 837 |
|
| 838 |
class Foo25 : IE25 |
| 839 |
{ |
| 840 |
char a() { return('a'); } |
| 841 |
char b() { return('b'); } |
| 842 |
char c() { return('c'); } |
| 843 |
char d() { return('d'); } |
| 844 |
char e() { return('e'); } |
| 845 |
} |
| 846 |
|
| 847 |
void test25() |
| 848 |
{ |
| 849 |
auto foo = new Foo25; |
| 850 |
printf("Foo: %c %c %c %c %c\n", foo.a, foo.b, foo.c, foo.d, foo.e); |
| 851 |
IA25 a = foo; |
| 852 |
printf("A: %c\n", a.a); |
| 853 |
assert(a.a == 'a'); |
| 854 |
IB25 b = foo; |
| 855 |
printf("B: %c\n", b.b); |
| 856 |
assert(b.b == 'b'); |
| 857 |
IC25 c = foo; |
| 858 |
printf("C: %c %c %c\n", c.a, c.b, c.c); |
| 859 |
assert(c.a == 'a'); |
| 860 |
assert(c.b == 'b'); |
| 861 |
assert(c.c == 'c'); |
| 862 |
ID25 d = foo; |
| 863 |
printf("D: %c\n", d.d); |
| 864 |
assert(d.d == 'd'); |
| 865 |
IE25 e = foo; |
| 866 |
printf("E: %c %c %c %c %c\n", e.a, e.b, e.c, e.d, e.e); |
| 867 |
assert(e.a == 'a'); |
| 868 |
assert(e.b == 'b'); |
| 869 |
assert(e.c == 'c'); |
| 870 |
assert(e.d == 'd'); |
| 871 |
assert(e.e == 'e'); |
| 872 |
|
| 873 |
b = e; |
| 874 |
printf("IB25: %c\n", b.b); |
| 875 |
assert(b.b == 'b'); |
| 876 |
} |
| 877 |
|
| 878 |
/*******************************************************/ |
| 879 |
|
| 880 |
interface VisualElement { |
| 881 |
void draw(); |
| 882 |
} |
| 883 |
|
| 884 |
interface Actor { |
| 885 |
} |
| 886 |
|
| 887 |
interface VisualActor : Actor, VisualElement { |
| 888 |
} |
| 889 |
|
| 890 |
class Sprite3 : Actor, VisualActor { |
| 891 |
override void draw() { } |
| 892 |
} |
| 893 |
|
| 894 |
void test26() |
| 895 |
{ |
| 896 |
} |
| 897 |
|
| 898 |
/*******************************************************/ |
| 899 |
|
| 900 |
interface I27 |
| 901 |
{ |
| 902 |
static int foo() { return 3; } |
| 903 |
|
| 904 |
final int bar() { return 7 + abc(); } |
| 905 |
|
| 906 |
int abc(); |
| 907 |
} |
| 908 |
|
| 909 |
class C27 : I27 |
| 910 |
{ |
| 911 |
int x; |
| 912 |
int abc() { return x * 10; } |
| 913 |
} |
| 914 |
|
| 915 |
void test27() |
| 916 |
{ |
| 917 |
C27 c = new C27(); |
| 918 |
c.x = 8; |
| 919 |
I27 i = c; |
| 920 |
assert(i.foo() == 3); |
| 921 |
assert(I27.foo() == 3); |
| 922 |
assert(i.bar() == 87); |
| 923 |
} |
| 924 |
|
| 925 |
/*******************************************************/ |
| 926 |
// https://issues.dlang.org/show_bug.cgi?id=1747 |
| 927 |
// https://issues.dlang.org/show_bug.cgi?id=2013 |
| 928 |
|
| 929 |
void test1747() |
| 930 |
{ |
| 931 |
interface IA { int mA(); } |
| 932 |
interface IB : IA { int mB(); } |
| 933 |
interface IC : IB { } |
| 934 |
interface ID : IA, IC { int mD(); } |
| 935 |
|
| 936 |
// offset: 0 +n +n + ptrsize |
| 937 |
// (IA) |
| 938 |
// IB |
| 939 |
// IA, IC |
| 940 |
static class C : ID |
| 941 |
{ |
| 942 |
int mA() { return 1; } |
| 943 |
int mB() { return 2; } |
| 944 |
int mD() { return 3; } |
| 945 |
} |
| 946 |
|
| 947 |
C c = new C; void* pc = *cast(void**)&c; |
| 948 |
ID id = c; void* pid = *cast(void**)&id; |
| 949 |
IC ic = c; void* pic = *cast(void**)⁣ |
| 950 |
IB ib = c; void* pib = *cast(void**)&ib; |
| 951 |
IA ia = c; void* pia = *cast(void**)&ia; |
| 952 |
|
| 953 |
//printf(" c = %p\n", pc); |
| 954 |
//printf("id = %p\n", pid); |
| 955 |
//printf("ic = %p\n", pic); |
| 956 |
//printf("ib = %p\n", pib); |
| 957 |
//printf("ia = %p\n", pia); |
| 958 |
|
| 959 |
size_t n = pid - pc; |
| 960 |
assert(pic == pc + n + (void*).sizeof); |
| 961 |
assert(pib == pc + n + (void*).sizeof); // OK <- NG |
| 962 |
assert(pia == pc + n); |
| 963 |
|
| 964 |
assert(id.mA() == 1); |
| 965 |
assert(id.mB() == 2); // OK <- NG (https://issues.dlang.org/show_bug.cgi?id=2013 case) |
| 966 |
assert(id.mD() == 3); |
| 967 |
|
| 968 |
assert(ic.mA() == 1); |
| 969 |
assert(ic.mB() == 2); // OK <- NG (https://issues.dlang.org/show_bug.cgi?id=2013 case) |
| 970 |
|
| 971 |
assert(ib.mA() == 1); |
| 972 |
assert(ib.mB() == 2); // OK <- NG |
| 973 |
|
| 974 |
assert(ia.mA() == 1); |
| 975 |
} |
| 976 |
|
| 977 |
/*******************************************************/ |
| 978 |
|
| 979 |
private interface IFoo |
| 980 |
{ |
| 981 |
void foo(); |
| 982 |
} |
| 983 |
|
| 984 |
void test2553() |
| 985 |
{ |
| 986 |
IFoo foo; |
| 987 |
if (0) |
| 988 |
foo.foo; |
| 989 |
} |
| 990 |
|
| 991 |
/*******************************************************/ |
| 992 |
|
| 993 |
interface I2524 |
| 994 |
{ |
| 995 |
void foo(); |
| 996 |
} |
| 997 |
|
| 998 |
class C2524 : I2524 |
| 999 |
{ |
| 1000 |
final override void foo() { } |
| 1001 |
} |
| 1002 |
|
| 1003 |
/*******************************************************/ |
| 1004 |
|
| 1005 |
interface Test4088 {} |
| 1006 |
|
| 1007 |
bool foo4088(Test4088 x, Test4088 y) |
| 1008 |
{ |
| 1009 |
return x == y; |
| 1010 |
} |
| 1011 |
|
| 1012 |
/*******************************************************/ |
| 1013 |
// https://issues.dlang.org/show_bug.cgi?id=7950 |
| 1014 |
|
| 1015 |
template TypeTuple7950(T...){alias T TypeTuple7950;} |
| 1016 |
interface I7950a {} // ok |
| 1017 |
interface I7950b : I7950a, TypeTuple7950!() {} // fail |
| 1018 |
|
| 1019 |
/*******************************************************/ |
| 1020 |
// https://issues.dlang.org/show_bug.cgi?id=10007 |
| 1021 |
|
| 1022 |
struct A10007 {} |
| 1023 |
|
| 1024 |
interface IFoo10007 |
| 1025 |
{ |
| 1026 |
void bar(ref const A10007); |
| 1027 |
} |
| 1028 |
|
| 1029 |
class Foo10007 : IFoo10007 |
| 1030 |
{ |
| 1031 |
void bar(ref const A10007 a) {} |
| 1032 |
void bar( const A10007 a) { return this.bar(a); } |
| 1033 |
} |
| 1034 |
|
| 1035 |
/*******************************************************/ |
| 1036 |
// https://issues.dlang.org/show_bug.cgi?id=10744 |
| 1037 |
|
| 1038 |
interface A10744 |
| 1039 |
{ |
| 1040 |
int x(); |
| 1041 |
Foo10744 foo(); |
| 1042 |
} |
| 1043 |
|
| 1044 |
class B10744 : A10744 |
| 1045 |
{ |
| 1046 |
int x() { return 0; } |
| 1047 |
Bar10744 foo() { return null; } |
| 1048 |
} |
| 1049 |
|
| 1050 |
class Foo10744 { } |
| 1051 |
class Bar10744 : Foo10744 { } |
| 1052 |
|
| 1053 |
interface C10744 |
| 1054 |
{ |
| 1055 |
int x(); |
| 1056 |
Baz10744 foo(); |
| 1057 |
} |
| 1058 |
|
| 1059 |
class D10744 : C10744 |
| 1060 |
{ |
| 1061 |
int x() { return 0; } |
| 1062 |
Qux10744 foo() { return null; } |
| 1063 |
} |
| 1064 |
|
| 1065 |
interface Baz10744 { } |
| 1066 |
interface Qux10744 : Baz10744 { } |
| 1067 |
|
| 1068 |
/*******************************************************/ |
| 1069 |
// https://issues.dlang.org/show_bug.cgi?id=11034 |
| 1070 |
|
| 1071 |
class A11034(T) |
| 1072 |
{ |
| 1073 |
A11034!int view() { return null; } |
| 1074 |
} |
| 1075 |
class B11034(T) : A11034!int |
| 1076 |
{ |
| 1077 |
override: |
| 1078 |
C11034!int view() { return null; } |
| 1079 |
} |
| 1080 |
class C11034(T) : B11034!int {} |
| 1081 |
|
| 1082 |
void test11034() |
| 1083 |
{ |
| 1084 |
auto b = new B11034!int; |
| 1085 |
|
| 1086 |
// Check that B!int.view() overrides A!int.view() |
| 1087 |
auto tiobj = typeid(Object); |
| 1088 |
assert(typeid(A11034!int).vtbl.length == tiobj.vtbl.length + 1); |
| 1089 |
assert(typeid(B11034!int).vtbl.length == tiobj.vtbl.length + 1); |
| 1090 |
} |
| 1091 |
|
| 1092 |
/*******************************************************/ |
| 1093 |
|
| 1094 |
void testTypeid() |
| 1095 |
{ |
| 1096 |
interface I |
| 1097 |
{ |
| 1098 |
} |
| 1099 |
|
| 1100 |
interface J : I |
| 1101 |
{ |
| 1102 |
} |
| 1103 |
|
| 1104 |
class C : J |
| 1105 |
{ |
| 1106 |
} |
| 1107 |
|
| 1108 |
class D : C |
| 1109 |
{ |
| 1110 |
} |
| 1111 |
|
| 1112 |
D d = new D(); |
| 1113 |
Object o = d; |
| 1114 |
I i = d; |
| 1115 |
|
| 1116 |
assert(typeid(typeof(o)) is typeid(Object)); |
| 1117 |
assert(typeid(o) is typeid(D)); |
| 1118 |
assert(o.classinfo is typeid(D)); |
| 1119 |
assert(typeid(typeof(i)) is typeid(I)); |
| 1120 |
assert(typeid(i) !is typeid(J)); |
| 1121 |
assert(i.classinfo !is typeid(J)); |
| 1122 |
} |
| 1123 |
|
| 1124 |
/*******************************************************/ |
| 1125 |
|
| 1126 |
extern (C++) |
| 1127 |
{ |
| 1128 |
interface IA47 |
| 1129 |
{ |
| 1130 |
char a(); |
| 1131 |
} |
| 1132 |
|
| 1133 |
interface IB47 |
| 1134 |
{ |
| 1135 |
char b(); |
| 1136 |
} |
| 1137 |
|
| 1138 |
interface IC47 : IA47, IB47 |
| 1139 |
{ |
| 1140 |
char c(); |
| 1141 |
} |
| 1142 |
|
| 1143 |
interface ID47 |
| 1144 |
{ |
| 1145 |
char d(); |
| 1146 |
} |
| 1147 |
|
| 1148 |
interface IE47 : IC47, ID47 |
| 1149 |
{ |
| 1150 |
char e(); |
| 1151 |
} |
| 1152 |
|
| 1153 |
class Foo47 : IE47 |
| 1154 |
{ |
| 1155 |
int x = 9; |
| 1156 |
char a() { printf("a.this = %p\n", this); return('a'); } |
| 1157 |
char b() { printf("b.this = %p\n", this); return('b'); } |
| 1158 |
char c() { printf("c.this = %p\n", this); return('c'); } |
| 1159 |
char d() { printf("d.this = %p\n", this); return('d'); } |
| 1160 |
char e() { printf("e.this = %p\n", this); return('e'); } |
| 1161 |
} |
| 1162 |
} |
| 1163 |
|
| 1164 |
void test15647() |
| 1165 |
{ |
| 1166 |
auto foo = new Foo47; |
| 1167 |
printf("Foo: %p %c %c %c %c %c\n", foo, foo.a, foo.b, foo.c, foo.d, foo.e); |
| 1168 |
IA47 a = foo; |
| 1169 |
printf("A: %c\n", a.a); |
| 1170 |
assert(a.a == 'a'); |
| 1171 |
IB47 b = foo; |
| 1172 |
printf("B: %c\n", b.b); |
| 1173 |
assert(b.b == 'b'); |
| 1174 |
IC47 c = foo; |
| 1175 |
printf("C: %p %c %c %c\n", c, c.a, c.b, c.c); |
| 1176 |
assert(c.a == 'a'); |
| 1177 |
assert(c.b == 'b'); |
| 1178 |
assert(c.c == 'c'); |
| 1179 |
ID47 d = foo; |
| 1180 |
printf("D: %c\n", d.d); |
| 1181 |
assert(d.d == 'd'); |
| 1182 |
IE47 e = foo; |
| 1183 |
printf("E: %c %c %c %c %c\n", e.a, e.b, e.c, e.d, e.e); |
| 1184 |
assert(e.a == 'a'); |
| 1185 |
assert(e.b == 'b'); |
| 1186 |
assert(e.c == 'c'); |
| 1187 |
assert(e.d == 'd'); |
| 1188 |
assert(e.e == 'e'); |
| 1189 |
|
| 1190 |
b = e; |
| 1191 |
printf("IB47: %c\n", b.b); |
| 1192 |
assert(b.b == 'b'); |
| 1193 |
} |
| 1194 |
|
| 1195 |
/*******************************************************/ |
| 1196 |
|
| 1197 |
int main() |
| 1198 |
{ |
| 1199 |
test1(); |
| 1200 |
test2(); |
| 1201 |
test3(); |
| 1202 |
test4(); |
| 1203 |
test5(); |
| 1204 |
test6(); |
| 1205 |
test7(); |
| 1206 |
test8(); |
| 1207 |
test9(); |
| 1208 |
test10(); |
| 1209 |
test11(); |
| 1210 |
test12(); |
| 1211 |
test13(); |
| 1212 |
test14(); |
| 1213 |
test15(); |
| 1214 |
test16(); |
| 1215 |
test17(); |
| 1216 |
test18(); |
| 1217 |
test19(); |
| 1218 |
test20(); |
| 1219 |
test21(); |
| 1220 |
test22(); |
| 1221 |
test23(); |
| 1222 |
test24(); |
| 1223 |
test25(); |
| 1224 |
test26(); |
| 1225 |
test27(); |
| 1226 |
test1747(); |
| 1227 |
test2553(); |
| 1228 |
test11034(); |
| 1229 |
testTypeid(); |
| 1230 |
test15647(); |
| 1231 |
|
| 1232 |
printf("Success\n"); |
| 1233 |
return 0; |
| 1234 |
} |