1 /// Copyright: Copyright (c) 2017-2019 Andrey Penechko. 2 /// License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0). 3 /// Authors: Andrey Penechko. 4 module tests.failing; 5 6 import tester; 7 8 Test[] failingTests() { return collectTests!(tests.failing)(); } 9 10 11 @TestInfo() 12 immutable fail1 = ` 13 --- fail1 14 "dddd 15 --- <error> 16 fail1:1:2: Error: Unexpected end of input inside string literal 17 `; 18 19 20 @TestInfo() 21 immutable fail2 = ` 22 --- fail2 23 /* 24 --- <error> 25 fail2:1:2: Error: Unterminated multiline comment 26 `; 27 28 29 @TestInfo() 30 immutable fail3 = r" 31 --- fail3 32 struct 33 --- <error> 34 fail3:2:1: Error: Expected `IDENTIFIER` token, while got `EOI` token 'end of input' 35 "; 36 37 38 @TestInfo() 39 immutable fail4 = r" 40 --- fail4 41 int a = ; 42 --- <error> 43 fail4:1:10: Error: SEMICOLON is not an expression 44 "; 45 46 47 @TestInfo() 48 immutable fail5 = r" 49 --- fail5 50 int[ a; 51 --- <error> 52 fail5:1:8: Error: Expected `RBRACKET` token, while got `SEMICOLON` token ';' 53 "; 54 55 56 @TestInfo() 57 immutable fail6 = r" 58 --- fail6 59 int[] ; 60 --- <error> 61 fail6:1:8: Error: Expected `IDENTIFIER` token, while got `SEMICOLON` token ';' 62 "; 63 64 65 @TestInfo() 66 immutable fail7 = r" 67 --- fail7 68 int[8 ; 69 --- <error> 70 fail7:1:8: Error: Expected `RBRACKET` token, while got `SEMICOLON` token ';' 71 "; 72 73 74 @TestInfo() 75 immutable fail8 = r" 76 --- fail8 77 struct test 78 --- <error> 79 fail8:2:1: Error: Expected `LCURLY` token, while got `EOI` token 'end of input' 80 "; 81 82 83 @TestInfo() 84 immutable fail9 = r" 85 --- fail9 86 struct test { 87 --- <error> 88 fail9:2:1: Error: Expected `RCURLY` token, while got `EOI` token 'end of input' 89 "; 90 91 92 @TestInfo() 93 immutable fail10 = r" 94 --- fail10 95 i32 fun( 96 --- <error> 97 fail10:2:1: Error: Expected `RPAREN` token, while got `EOI` token 'end of input' 98 "; 99 100 101 @TestInfo() 102 immutable fail11 = r" 103 --- fail11 104 i32 fun(){ 105 --- <error> 106 fail11:2:1: Error: Expected `RCURLY` token, while got `EOI` token 'end of input' 107 "; 108 109 110 @TestInfo() 111 immutable fail12 = r" 112 --- fail12 113 i32 fun(){ 114 a = b + 115 --- <error> 116 fail12:3:1: Error: Unexpected end of input 117 "; 118 119 120 @TestInfo() 121 immutable fail13 = r" 122 --- fail13 123 i32 fun(){ 124 a = b + c 125 --- <error> 126 fail13:3:1: Error: Expected `SEMICOLON` token, while got `EOI` token 'end of input' 127 "; 128 129 @TestInfo() 130 immutable fail14 = r" 131 --- fail14 132 i32 fun(){ 133 /* 134 */ 135 bar(); 136 } 137 --- <error> 138 fail14:4:3: Error: undefined identifier `bar` 139 "; 140 141 @TestInfo() 142 immutable fail15 = r" 143 --- fail15 144 void run() { 145 i32 val1 = 0; 146 i32 flags = 1; 147 if (val1 & flags != flags) {} 148 } 149 --- <error> 150 fail15:4:12: Error: Cannot perform `i32` & `bool` operation 151 "; 152 153 @TestInfo() 154 immutable fail16 = q{ 155 --- fail16 156 // Test argument checking for pointers 157 void usePtru8(u8*){} 158 void usePtru16(u16*){} 159 void usePtru32(u32*){} 160 void usePtru64(u64*){} 161 void run() { 162 u8 num8 = 10; 163 usePtru8(&num8); 164 usePtru16(&num8); 165 usePtru32(&num8); 166 usePtru64(&num8); 167 } 168 --- <error> 169 fail16:9:13: Error: Argument 1, must have type u16*, not u8* 170 fail16:10:13: Error: Argument 1, must have type u32*, not u8* 171 fail16:11:13: Error: Argument 1, must have type u64*, not u8* 172 }; 173 174 @TestInfo() 175 immutable fail17 = q{ 176 --- fail17 177 // Test instantiation of opaque structs 178 struct Opaque; 179 Opaque op_global; 180 Opaque op_return(Opaque op_param) { 181 Opaque op_local; 182 return op_local; 183 } 184 --- <error> 185 fail17:3:9: Error: cannot declare variable `op_global` of opaque type `Opaque` 186 fail17:4:9: Error: function cannot return opaque type `Opaque` 187 fail17:4:26: Error: cannot declare parameter of opaque type `Opaque` 188 fail17:5:10: Error: cannot declare variable `op_local` of opaque type `Opaque` 189 }; 190 191 @TestInfo() 192 immutable fail18 = q{ 193 --- fail18 194 // Test for loop. Init declaration must not escape 195 i32 test() { 196 for (i32 i = 0; i < 10; ++i) {} 197 return i; 198 } 199 --- <error> 200 fail18:4:10: Error: undefined identifier `i` 201 }; 202 203 @TestInfo() 204 immutable fail19 = q{ 205 --- fail19 206 enum enumT : u32 { 207 } 208 // Test access to non-existing enum member 209 u32 test() { 210 return enumT.ESCAPE; 211 } 212 --- <error> 213 fail19:5:15: Error: `enumT` has no member `ESCAPE` 214 }; 215 216 @TestInfo() 217 immutable fail20 = q{ 218 --- fail20 219 enum enumT : u32 { 220 } 221 // Test access to non-existing enum member that is used in expression 222 void test() { 223 if (enumT.ESCAPE == 0) { 224 } 225 } 226 --- <error> 227 fail20:5:12: Error: `enumT` has no member `ESCAPE` 228 }; 229 230 @TestInfo() 231 immutable fail21 = q{ 232 --- fail21 233 struct S { 234 u16 num; 235 } 236 // Test wrong constructor argument type 237 void test() { 238 S s = S("string"); 239 } 240 --- <error> 241 fail21:6:11: Error: argument for member `num`, must have type u16, not u8[] 242 }; 243 244 @TestInfo() 245 immutable fail22 = q{ 246 --- fail22 247 // Test return null when int is expected 248 u32 test() { 249 return null; 250 } 251 --- <error> 252 fail22:3:3: Error: Cannot implicitly convert expression of type `typeof(null)` to `u32` 253 }; 254 255 @TestInfo() 256 immutable fail23 = q{ 257 --- fail23 258 // Test default argument is expected, unnamed parameter 259 void test(u32 arg1 = 42, u32) {} 260 --- <error> 261 fail23:2:27: Error: Default argument expected for __param_1 262 }; 263 264 @TestInfo() 265 immutable fail24 = q{ 266 --- fail24 267 // Test default argument is expected 268 void test(u32 arg1 = 42, u32 arg2) {} 269 --- <error> 270 fail24:2:31: Error: Default argument expected for arg2 271 }; 272 273 @TestInfo() 274 immutable fail25 = q{ 275 --- fail25 276 // Test insufficient args with default args 277 void func(u32 arg1, u32 arg2 = 42) {} 278 void test() { func(); } 279 --- <error> 280 fail25:3:20: Error: Too few arguments to `func`, got 0, expected 1-2 281 }; 282 283 @TestInfo() 284 immutable fail26 = q{ 285 --- fail26 286 // Test excessive arguments 287 void func(u32 arg1 = 42) {} 288 void test() { func(1, 2); } 289 --- <error> 290 fail26:3:20: Error: Too many arguments to `func`, got 2, expected 0-1 291 }; 292 293 @TestInfo() 294 immutable fail27 = q{ 295 --- fail27 296 // Test excessive arguments 297 void func(u32 arg1) {} 298 void test() { func(1, 2); } 299 --- <error> 300 fail27:3:20: Error: Too many arguments to `func`, got 2, expected 1 301 }; 302 303 @TestInfo() 304 immutable fail28 = q{ 305 --- fail28 306 // Test ; as empty statement 307 void test() { if(true); } 308 --- <error> 309 fail28:2:24: Error: Cannot use `;` as an empty statement. Use `{}` instead 310 }; 311 312 @TestInfo() 313 immutable fail29 = q{ 314 --- fail29 315 // Unknown identifiers 316 Array[Point] array; 317 --- <error> 318 fail29:2:2: Error: undefined identifier `Array` 319 fail29:2:8: Error: undefined identifier `Point` 320 }; 321 322 323 @TestInfo() 324 immutable fail30 = q{ 325 --- fail30 326 // Call used as a type. Example 327 // a() <-- missing semicolon 328 // b ... 329 void run() { 330 a() b; 331 } 332 --- <error> 333 fail30:5:7: Error: Invalid expression. Missing `;` before `b` 334 }; 335 336 337 @TestInfo() 338 immutable fail31 = q{ 339 --- fail31 340 #assert 42 341 --- <error> 342 fail31:1:10: Error: Expected `(` after #assert, while got `42` 343 }; 344 345 @TestInfo() 346 immutable fail32 = q{ 347 --- fail32 348 #assert(42 349 --- <error> 350 fail32:2:1: Error: Expected `,` after condition of #assert, while got `end of input` 351 }; 352 353 @TestInfo() 354 immutable fail33 = q{ 355 --- fail33 356 #assert(42, ) 357 --- <error> 358 fail33:1:14: Error: RPAREN is not an expression 359 }; 360 361 @TestInfo() 362 immutable fail34 = q{ 363 --- fail34 364 #assert(42, "message") 365 --- <error> 366 fail34:2:1: Error: Expected `;` after #assert, while got `end of input` 367 }; 368 369 @TestInfo() 370 immutable fail35 = q{ 371 --- fail35 372 #assert(42, 42); 373 --- <error> 374 fail35:1:2: Error: #assert only supports string literal as a message 375 }; 376 377 378 @TestInfo() 379 immutable fail36 = q{ 380 --- fail36 381 // Should not return from noreturn 382 noreturn run() { 383 return foo; 384 } 385 i32 foo(){ return 42; } 386 --- <error> 387 fail36:3:3: Error: Cannot implicitly convert expression of type `i32` to `noreturn` 388 }; 389 390 391 @TestInfo() 392 immutable fail37 = q{ 393 --- fail37 394 // Non-type used as return type 395 alias type1 = getType1; 396 $alias getType1() { return u8; } 397 type1 run1() { 398 return 42; 399 } 400 --- <error> 401 fail37:2:16: Error: function is not a type 402 }; 403 404 405 @TestInfo() 406 immutable fail38 = q{ 407 --- fail38 408 // Non-type used as var type 409 $alias getType1() { return u8; } 410 alias type1 = getType1; 411 type1 var; 412 --- <error> 413 fail38:3:16: Error: function is not a type 414 }; 415 416 417 @TestInfo() 418 @(TargetOs.linux) 419 immutable fail39 = q{--- fail39 420 // 2 Extern syscall attributes 421 @extern(syscall, 60) 422 @extern(syscall, 100) 423 void exit(); 424 --- <error> 425 fail39:3:2: Error: Duplicate @extern attribute 426 }; 427 428 429 @TestInfo() 430 @(TargetOs.windows) 431 immutable fail40 = q{--- fail40 432 // Should fail on Windows target 433 @extern(syscall, 60) 434 void exit(); 435 --- <error> 436 fail40:2:2: Error: @extern(syscall) attribute is only implemented on linux 437 }; 438 439 440 @TestInfo() 441 immutable fail41 = q{--- fail41 442 import unknown; 443 --- <error> 444 fail41:1:2: Error: Cannot find module `unknown` 445 }; 446 447 448 @TestInfo() 449 immutable fail42 = q{--- fail42 450 enum e7 : i32 { e7 = 7 } // type 451 enum e9 { e9 = 9 } // type 452 void accept_e9(e9){} 453 void run() { 454 accept_e9(e7.e7); 455 } 456 --- <error> 457 fail42:5:15: Error: Argument 1, must have type e9, not e7 458 }; 459 460 461 @TestInfo() 462 immutable fail43 = q{--- fail43 463 enum e9 { e9 = 9 } // type 464 void accept_e9(e9){} 465 void run() { 466 accept_e9(42); 467 } 468 --- <error> 469 fail43:4:13: Error: Argument 1, must have type e9, not i32 470 }; 471 472 // packages 473 @TestInfo() 474 immutable fail44 = q{--- fail44/mod1.vx 475 module fail44.mod1; 476 module fail44.mod2; 477 --- <error> 478 fail44/mod1.vx:2:2: Error: Module declaration can only occur as first declaration of the module 479 }; 480 481 @TestInfo() 482 immutable fail45 = q{--- fail45/mod1.vx 483 module mod1; 484 --- fail45/mod2.vx 485 module mod1; 486 --- <error> 487 fail45/mod2.vx:1:2: Error: Module `mod1` in file fail45/mod2.vx conflicts with another module `mod1` in file fail45/mod1.vx 488 }; 489 490 @TestInfo() 491 immutable fail46 = q{--- fail46/mod1.vx 492 module fail46.mod1; 493 --- fail46/mod2.vx 494 module fail46.mod1; 495 --- <error> 496 fail46/mod2.vx:1:2: Error: Module `fail46.mod1` in file fail46/mod2.vx conflicts with another module `fail46.mod1` in file fail46/mod1.vx 497 }; 498 499 @TestInfo() 500 immutable fail47 = q{--- fail47/mod1.vx 501 module fail47.mod1; 502 --- fail47/mod2.vx 503 module fail47; 504 --- <error> 505 fail47/mod2.vx:1:2: Error: Module `fail47` in file fail47/mod2.vx conflicts with package `fail47` in files fail47/mod1.vx 506 }; 507 508 @TestInfo() 509 immutable fail48 = q{--- fail48/mod1.vx 510 module fail48; 511 --- fail48/mod2.vx 512 module fail48.mod2; 513 --- <error> 514 fail48/mod2.vx:1:2: Error: Module `fail48.mod2` in file fail48/mod2.vx conflicts with another module `fail48` in file fail48/mod1.vx 515 }; 516 517 @TestInfo() 518 immutable fail49 = q{--- fail49/mod1.vx 519 module fail49.sub.mod1; 520 --- fail49/mod2.vx 521 module fail49.sub; 522 --- <error> 523 fail49/mod2.vx:1:2: Error: Module `fail49.sub` in file fail49/mod2.vx conflicts with package `fail49.sub` in files fail49/mod1.vx 524 }; 525 526 @TestInfo() 527 immutable fail50 = q{--- fail50/mod1.vx 528 module fail50.sub; 529 --- fail50/mod2.vx 530 module fail50.sub.mod2; 531 --- <error> 532 fail50/mod2.vx:1:2: Error: Module `fail50.sub.mod2` in file fail50/mod2.vx conflicts with another module `fail50.sub` in file fail50/mod1.vx 533 }; 534 535 @TestInfo() 536 immutable fail51 = q{--- fail51/mod1.vx 537 module fail51.sub.mod1; 538 --- fail51/mod2.vx 539 module fail51; 540 --- <error> 541 fail51/mod2.vx:1:2: Error: Module `fail51` in file fail51/mod2.vx conflicts with package `fail51` in files fail51/mod1.vx 542 }; 543 544 @TestInfo() 545 immutable fail52 = q{--- fail52/mod1.vx 546 module fail52; 547 --- fail52/mod2.vx 548 module fail52.sub.mod2; 549 --- <error> 550 fail52/mod2.vx:1:2: Error: Module `fail52.sub.mod2` in file fail52/mod2.vx conflicts with another module `fail52` in file fail52/mod1.vx 551 }; 552 553 /* Unstable order 554 @TestInfo() 555 immutable fail53 = q{--- fail53/mod1.vx 556 module fail53.sub.mod1; 557 --- fail53/mod2.vx 558 module fail53.sub.mod2; 559 --- fail53/mod3.vx 560 module fail53.sub.mod3; 561 --- fail53/mod4.vx 562 module fail53; 563 --- <error> 564 fail53/mod4.vx:1:2: Error: Module `fail53` in file fail53/mod4.vx conflicts with package `fail53` in files fail53/mod2.vx, fail53/mod3.vx and 1 more 565 }; 566 567 568 @TestInfo() 569 immutable fail54 = q{--- fail54/mod1.vx 570 module fail54.sub.mod1; 571 --- fail54/mod2.vx 572 module fail54.sub.mod2; 573 --- fail54/mod3.vx 574 module fail54.sub.mod3; 575 --- fail54/mod4.vx 576 module fail54.sub.mod4; 577 --- fail54/mod5.vx 578 module fail54; 579 --- <error> 580 fail54:1:2: Error: Module `fail54` in file fail54/mod5.vx conflicts with package `fail54` in files fail54/mod4.vx, fail54/mod1.vx and 2 more 581 };*/ 582 583 584 // package imports 585 @TestInfo() 586 immutable fail55 = q{--- fail55/mod1.vx 587 module fail55.mod1; 588 --- fail55/mod2.vx 589 module fail55.mod2; 590 import fail55; 591 --- <error> 592 fail55/mod2.vx:2:2: Error: Cannot import package `fail55` 593 }; 594 595 @TestInfo() 596 immutable fail56 = q{--- fail56/mod1.vx 597 module fail56.mod1; 598 --- fail56/mod2.vx 599 module fail56.mod2; 600 import fail56.mod1.mod1; 601 --- <error> 602 fail56/mod2.vx:2:2: Error: Cannot find module `fail56.mod1.mod1`. But there is module with name `fail56.mod1` 603 }; 604 605 606 @TestInfo() 607 immutable fail57 = q{--- fail57.vx 608 ; 609 --- <error> 610 fail57.vx:1:2: Error: SEMICOLON is not an expression 611 }; 612 613 614 @TestInfo() 615 immutable fail58 = q{--- fail58.vx 616 // indexing struct 617 struct S[T] {} 618 u8* run() { 619 S[u8*] s; 620 s[0]; 621 } 622 --- <error> 623 fail58.vx:5:4: Error: Cannot index value of type `S[u8*]` 624 }; 625 626 627 @TestInfo() 628 immutable fail59 = q{--- fail59 629 // Returning a type instead of a type instance 630 struct S{} 631 S run() { 632 return S; 633 } 634 --- <error> 635 fail59:4:3: Error: Cannot implicitly convert expression of type `$type` to `S` 636 }; 637 638 639 @TestInfo() 640 immutable fail60 = q{--- fail60 641 // Trying to define extern module function 642 @extern(module, "kernel32") 643 u8 getByte() { 644 return 10; 645 } 646 --- <error> 647 fail60:3:5: Error: External function cannot have a body 648 }; 649 650 651 @TestInfo() 652 @(TargetOs.linux) 653 immutable fail61 = q{--- fail61 654 // 2 Extern attributes 655 @extern(module, "kernel32") 656 @extern(syscall, 60) 657 void exit(); 658 --- <error> 659 fail61:3:2: Error: Duplicate @extern attribute 660 }; 661 662 663 @TestInfo() 664 @(TargetOs.linux) 665 immutable fail62 = q{--- fail62 666 // Trying to define extern syscall function 667 @extern(syscall, 50) 668 u8 mmap() { 669 return 10; 670 } 671 --- <error> 672 fail62:3:5: Error: External function cannot have a body 673 }; 674 675 676 @TestInfo() 677 @(TargetOs.linux) 678 immutable fail63 = q{--- fail63 679 /// Broadcasting @extern(syscall) is forbidden 680 @extern(syscall, 0): 681 void withAttribA(); 682 --- <error> 683 fail63:2:2: Error: Broadcasting @extern(syscall) attribute is forbidden 684 }; 685 686 687 @TestInfo() 688 immutable fail64 = q{--- fail64 689 /// Bug #20. Crash 690 u32 hey; 691 $alias getHey() { 692 return $alias(hey); 693 } 694 --- <error> 695 fail64:4:16: Error: Cannot call basic type 696 }; 697 698 699 @TestInfo() 700 immutable fail65 = q{--- fail65 701 /// Error for external function without @extern annotation 702 void external(); 703 --- <error> 704 fail65:2:7: Error: External function `external` must be annotated with @extern attribute 705 }; 706 707 708 @TestInfo() 709 immutable fail66 = q{--- fail66 710 /// Error for external function pointing to non-existing module 711 @extern(module, "non_existing") 712 void external(); 713 --- <error> 714 fail66:3:7: Error: Cannot find external symbol `external` in host module `non_existing`. No such module defined 715 }; 716 717 718 @TestInfo(null, [HostSymbol("external_noop", cast(void*)&external_noop)]) 719 immutable fail67 = q{--- fail67 720 /// Error for external function pointing to non-existing function in existing module 721 @extern(module, "host") 722 void external(); 723 --- <error> 724 fail67:3:7: Error: Cannot find external symbol `external` in host module `host` 725 }; 726 727 728 @TestInfo() 729 immutable fail68 = q{--- fail68 730 /// Attribute scope. Check that attribute block doesn't introduce a scope. Checked with double definition 731 @extern(module, "host") { 732 void foo(){} 733 } 734 void foo(){} 735 --- <error> 736 fail68:5:7: Error: declaration `foo` is already defined at fail68:3:8 737 }; 738 739 740 @TestInfo() 741 immutable fail69 = q{--- fail69 742 bool run(u8* s) { 743 u8 c; 744 return (c = *s++) != '\0'; 745 } 746 --- <error> 747 fail69:3:21: Error: Cannot compare `void` and `i32` 748 };