1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 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 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786
|
// First, test everything together.
//
// RUN: %target-typecheck-verify-swift
// Now to the cross-module test. The result builder and protocols go to the
// module, the rest to the importing file.
//
// RUN: %empty-directory(%t)
// RUN: %empty-directory(%t/src)
// RUN: split-file %s %t/src
//
// RUN: %target-swift-frontend -emit-module -module-name M -emit-module-path %t/M.swiftmodule %t/src/M.swift
// RUN: %target-swift-frontend -typecheck -verify -I %t -D CROSS_MODULE %t/src/test.swift
//--- M.swift
public struct Result {
public init() {}
}
@resultBuilder
public enum Builder<T> {
public static func buildBlock(_: T...) -> Result { Result() }
}
public protocol P_Builder_Int1 {
@Builder<Int>
func function() -> Result
@Builder<Int>
var property1: Result { get }
var property2: Result { @Builder<Int> get }
@Builder<Int>
subscript(subscript1 _: Int) -> Result { get }
subscript(subscript2 _: Int) -> Result { @Builder<Int> get }
}
public protocol P_Builder_Int2 {
@Builder<Int>
func function() -> Result
@Builder<Int>
var property1: Result { get }
var property2: Result { @Builder<Int> get }
@Builder<Int>
subscript(subscript1 _: Int) -> Result { get }
subscript(subscript2 _: Int) -> Result { @Builder<Int> get }
}
public protocol P_Builder_String {
@Builder<String>
func function() -> Result
@Builder<String>
var property1: Result { get }
var property2: Result { @Builder<String> get }
@Builder<String>
subscript(subscript1 _: Int) -> Result { get }
subscript(subscript2 _: Int) -> Result { @Builder<String> get }
}
public protocol P_Builder_Bool {
@Builder<Bool>
func function() -> Result
@Builder<Bool>
var property1: Result { get }
var property2: Result { @Builder<Bool> get }
@Builder<Bool>
subscript(subscript1 _: Int) -> Result { get }
subscript(subscript2 _: Int) -> Result { @Builder<Bool> get }
}
//--- test.swift
#if CROSS_MODULE
import M
#endif
// Result builder cannot be inferred from overridden declaration.
do {
class Super {
@Builder<Int> func function() -> Result { 1 }
}
class Sub: Super {
override public func function() -> Result { Result() }
}
}
// Result builder of dynamic replacement can be inferred from the replaced
// declaration.
struct Test1 {
@Builder<Int>
dynamic func function() -> Result { 1 }
@Builder<Int>
dynamic var property1: Result { 1 }
dynamic var property2: Result { @Builder<Int> get { 1 } }
@Builder<Int>
dynamic subscript(subscript1 _: Int) -> Result { 1 }
dynamic subscript(subscript2 _: Int) -> Result { @Builder<Int> get { 1 } }
}
extension Test1 {
@_dynamicReplacement(for: function)
func replacement_function() -> Result { 1 }
@_dynamicReplacement(for: property1)
var replacement_property1: Result { 1 }
@_dynamicReplacement(for: property2)
var replacement_property2: Result { 1 }
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { 1 }
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { 1 }
}
// Edge case: context is a protocol extension.
protocol Test1_1 {}
extension Test1_1 {
@Builder<Int>
dynamic func function() -> Result { 1 }
@_dynamicReplacement(for: function)
func replacement_function() -> Result { 1 }
}
// Result builders can be inferred from protocol requirements.
do {
struct Test: P_Builder_Int1 {
func function() -> Result { 1 }
var property1: Result { 1 }
var property2: Result { 1 }
subscript(subscript1 _: Int) -> Result { 1 }
subscript(subscript2 _: Int) -> Result { 1 }
}
}
// Exception: inference does not support function parameters.
do {
protocol P {
func function(@Builder<Int> _: () -> Result)
}
struct Test: P {
func function(_: () -> Result) {}
}
Test().function { Result() }
}
// Result builder of a dynamic replacement can be
// inferred from a protocol requirement that is witnessed by the replaced
// declaration.
struct Test2: P_Builder_Int1 {
dynamic func function() -> Result { 1 }
dynamic var property1: Result { 1 }
dynamic var property2: Result { 1 }
dynamic subscript(subscript1 _: Int) -> Result { 1 }
dynamic subscript(subscript2 _: Int) -> Result { 1 }
}
extension Test2 {
@_dynamicReplacement(for: function)
func replacement_function() -> Result { 1 }
@_dynamicReplacement(for: property1)
var replacement_property1: Result { 1 }
@_dynamicReplacement(for: property2)
var replacement_property2: Result { 1 }
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { 1 }
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { 1 }
}
// Inference from multiple conflicting sources with matching result builder
// types is unambiguous.
struct Test3: P_Builder_Int1, P_Builder_Int2 {
dynamic func function() -> Result { 1 }
dynamic var property1: Result { 1 }
dynamic var property2: Result { 1 }
dynamic subscript(subscript1 _: Int) -> Result { 1 }
dynamic subscript(subscript2 _: Int) -> Result { 1 }
}
extension Test3 {
@_dynamicReplacement(for: function)
func replacement_function() -> Result { 1 }
@_dynamicReplacement(for: property1)
var replacement_property1: Result { 1 }
@_dynamicReplacement(for: property2)
var replacement_property2: Result { 1 }
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { 1 }
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { 1 }
}
struct Test4 {
@Builder<Int> dynamic func replaced_function() -> Result { 1 }
@Builder<Int> dynamic var replaced_property1: Result { 1 }
@Builder<Int> dynamic var replaced_property2: Result { 1 }
@Builder<Int> dynamic subscript(replaced_subscript1 _: Int) -> Result { 1 }
@Builder<Int> dynamic subscript(replaced_subscript2 _: Int) -> Result { 1 }
}
extension Test4: P_Builder_Int1 {
@_dynamicReplacement(for: replaced_function)
func function() -> Result { 1 }
@_dynamicReplacement(for: replaced_property1)
var property1: Result { 1 }
@_dynamicReplacement(for: replaced_property2)
var property2: Result { 1 }
@_dynamicReplacement(for: subscript(replaced_subscript1:))
subscript(subscript1 _: Int) -> Result { 1 }
@_dynamicReplacement(for: subscript(replaced_subscript2:))
subscript(subscript2 _: Int) -> Result { 1 }
}
// Ambiguous inference.
struct Test5: P_Builder_Int1, P_Builder_Int2, P_Builder_String {
// expected-note@+6{{add an explicit 'return' statement to not use a result builder}}{{+1:3-3=return <#expr#>\n}}
// expected-note@+5{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{-1:3-3=@Builder<Int> }}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int2')}}{{-1:3-3=@Builder<Int> }} // FIXME: This is redundant; we already suggested Builder<Int>.
// expected-note@+3{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{-1:3-3=@Builder<String> }}
// expected-error@+2{{ambiguous result builder inferred for 'function()': 'Builder<Int>' or 'Builder<String>'}}
internal dynamic
func function() -> Result {
}
// FIXME: 'return' will be inserted without semicolon.
// expected-note@+6{{add an explicit 'return' statement to not use a result builder}}{{13-13=return <#expr#>\n}}
// expected-note@+5{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{-1:3-3=@Builder<Int> }}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int2')}}{{-1:3-3=@Builder<Int> }} // FIXME: This is redundant; we already suggested Builder<Int>.
// expected-note@+3{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{-1:3-3=@Builder<String> }}
// expected-error@+2{{ambiguous result builder inferred for 'property1': 'Builder<Int>' or 'Builder<String>'}}
dynamic var property1: Result {
get { 1 } // expected-error {{cannot convert return expression}}
}
// expected-note@+6{{add an explicit 'return' statement to not use a result builder}}{{10-10=return <#expr#>\n}}
// expected-note@+5{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{-1:3-3=@Builder<Int> }}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int2')}}{{-1:3-3=@Builder<Int> }} // FIXME: This is redundant; we already suggested Builder<Int>.
// expected-note@+3{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{-1:3-3=@Builder<String> }}
// expected-error@+2{{ambiguous result builder inferred for 'property2': 'Builder<Int>' or 'Builder<String>'}}
dynamic var property2: Result {
get {}
}
// expected-note@+5{{add an explicit 'return' statement to not use a result builder}}{{51-51=return <#expr#>\n}}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{3-3=@Builder<Int> }}
// expected-note@+3{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int2')}}{{3-3=@Builder<Int> }} // FIXME: This is redundant; we already suggested Builder<Int>.
// expected-note@+2{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{3-3=@Builder<String> }}
// expected-error@+1{{ambiguous result builder inferred for 'subscript(subscript1:)': 'Builder<Int>' or 'Builder<String>'}}
dynamic subscript(subscript1 _: Int) -> Result {}
// expected-note@+5{{add an explicit 'return' statement to not use a result builder}}{{+1:3-3=return <#expr#>\n}}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{3-3=@Builder<Int> }}
// expected-note@+3{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int2')}}{{3-3=@Builder<Int> }} // FIXME: This is redundant; we already suggested Builder<Int>.
// expected-note@+2{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{3-3=@Builder<String> }}
// expected-error@+1{{ambiguous result builder inferred for 'subscript(subscript2:)': 'Builder<Int>' or 'Builder<String>'}}
dynamic subscript(subscript2 _: Int) -> Result {
}
}
extension Test5 {
// expected-note@+6{{add an explicit 'return' statement to not use a result builder}}{{+1:3-3=return <#expr#>\n}}
// expected-note@+5{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{-1:3-3=@Builder<Int> }}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int2')}}{{-1:3-3=@Builder<Int> }} // FIXME: This is redundant; we already suggested Builder<Int>.
// expected-note@+3{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{-1:3-3=@Builder<String> }}
// expected-error@+2{{ambiguous result builder inferred for 'replacement_function()': 'Builder<Int>' or 'Builder<String>'}}
@_dynamicReplacement(for: function)
func replacement_function() -> Result {
}
// expected-note@+6{{add an explicit 'return' statement to not use a result builder}}{{+1:3-3=return <#expr#>\n}}
// expected-note@+5{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{-1:3-3=@Builder<Int> }}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int2')}}{{-1:3-3=@Builder<Int> }} // FIXME: This is redundant; we already suggested Builder<Int>.
// expected-note@+3{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{-1:3-3=@Builder<String> }}
// expected-error@+2{{ambiguous result builder inferred for 'replacement_property1': 'Builder<Int>' or 'Builder<String>'}}
@_dynamicReplacement(for: property1)
var replacement_property1: Result {
}
// expected-note@+6{{add an explicit 'return' statement to not use a result builder}}{{+1:3-3=return <#expr#>\n}}
// expected-note@+5{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{-1:3-3=@Builder<Int> }}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int2')}}{{-1:3-3=@Builder<Int> }} // FIXME: This is redundant; we already suggested Builder<Int>.
// expected-note@+3{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{-1:3-3=@Builder<String> }}
// expected-error@+2{{ambiguous result builder inferred for 'replacement_property2': 'Builder<Int>' or 'Builder<String>'}}
@_dynamicReplacement(for: property2)
var replacement_property2: Result {
}
// expected-note@+6{{add an explicit 'return' statement to not use a result builder}}{{+1:3-3=return <#expr#>\n}}
// expected-note@+5{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{-1:3-3=@Builder<Int> }}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int2')}}{{-1:3-3=@Builder<Int> }} // FIXME: This is redundant; we already suggested Builder<Int>.
// expected-note@+3{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{-1:3-3=@Builder<String> }}
// expected-error@+2{{ambiguous result builder inferred for 'subscript(replacement_subscript1:)': 'Builder<Int>' or 'Builder<String>'}}
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result {
}
// expected-note@+6{{add an explicit 'return' statement to not use a result builder}}{{+1:3-3=return <#expr#>\n}}
// expected-note@+5{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{-1:3-3=@Builder<Int> }}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int2')}}{{-1:3-3=@Builder<Int> }} // FIXME: This is redundant; we already suggested Builder<Int>.
// expected-note@+3{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{-1:3-3=@Builder<String> }}
// expected-error@+2{{ambiguous result builder inferred for 'subscript(replacement_subscript2:)': 'Builder<Int>' or 'Builder<String>'}}
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result {
}
}
struct Test6 {}
extension Test6: P_Builder_Int1, P_Builder_String {
// expected-note@+6{{add an explicit 'return' statement to not use a result builder}}{{+1:3-3=return <#expr#>\n}}
// expected-note@+5{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{-1:3-3=@Builder<String> }}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{-1:3-3=@Builder<Int> }}
// expected-note@+3{{apply result builder 'Builder<Bool>' (inferred from dynamic replacement of 'replaced_function()')}}{{-1:3-3=@Builder<Bool> }}
// expected-error@+2{{ambiguous result builder inferred for 'function()': 'Builder<Int>' or 'Builder<String>'}}
@_dynamicReplacement(for: replaced_function)
func function() -> Result {
}
// expected-note@+6{{add an explicit 'return' statement to not use a result builder}}{{+1:3-3=return <#expr#>\n}}
// expected-note@+5{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{-1:3-3=@Builder<String> }}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{-1:3-3=@Builder<Int> }}
// expected-note@+3{{apply result builder 'Builder<Bool>' (inferred from dynamic replacement of 'replaced_property1')}}{{-1:3-3=@Builder<Bool> }}
// expected-error@+2{{ambiguous result builder inferred for 'property1': 'Builder<Int>' or 'Builder<String>'}}
@_dynamicReplacement(for: replaced_property1)
var property1: Result {
}
// expected-note@+6{{add an explicit 'return' statement to not use a result builder}}{{+1:3-3=return <#expr#>\n}}
// expected-note@+5{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{-1:3-3=@Builder<String> }}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{-1:3-3=@Builder<Int> }}
// expected-note@+3{{apply result builder 'Builder<Bool>' (inferred from dynamic replacement of 'replaced_property2')}}{{-1:3-3=@Builder<Bool> }}
// expected-error@+2{{ambiguous result builder inferred for 'property2': 'Builder<Int>' or 'Builder<String>'}}
@_dynamicReplacement(for: replaced_property2)
var property2: Result {
}
// expected-note@+6{{add an explicit 'return' statement to not use a result builder}}{{+1:3-3=return <#expr#>\n}}
// expected-note@+5{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{-1:3-3=@Builder<String> }}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{-1:3-3=@Builder<Int> }}
// expected-note@+3{{apply result builder 'Builder<Bool>' (inferred from dynamic replacement of 'subscript(replaced_subscript1:)')}}{{-1:3-3=@Builder<Bool> }}
// expected-error@+2{{ambiguous result builder inferred for 'subscript(subscript1:)': 'Builder<Int>' or 'Builder<String>'}}
@_dynamicReplacement(for: subscript(replaced_subscript1:))
subscript(subscript1 _: Int) -> Result {
}
// expected-note@+6{{add an explicit 'return' statement to not use a result builder}}{{+1:3-3=return <#expr#>\n}}
// expected-note@+5{{apply result builder 'Builder<String>' (inferred from protocol 'P_Builder_String')}}{{-1:3-3=@Builder<String> }}
// expected-note@+4{{apply result builder 'Builder<Int>' (inferred from protocol 'P_Builder_Int1')}}{{-1:3-3=@Builder<Int> }}
// expected-note@+3{{apply result builder 'Builder<Bool>' (inferred from dynamic replacement of 'subscript(replaced_subscript2:)')}}{{-1:3-3=@Builder<Bool> }}
// expected-error@+2{{ambiguous result builder inferred for 'subscript(subscript2:)': 'Builder<Int>' or 'Builder<String>'}}
@_dynamicReplacement(for: subscript(replaced_subscript2:))
subscript(subscript2 _: Int) -> Result {
}
}
extension Test6 {
@Builder<Bool> dynamic func replaced_function() -> Result { true }
@Builder<Bool> dynamic var replaced_property1: Result { true }
@Builder<Bool> dynamic var replaced_property2: Result { true }
@Builder<Bool> dynamic subscript(replaced_subscript1 _: Int) -> Result { true }
@Builder<Bool> dynamic subscript(replaced_subscript2 _: Int) -> Result { true }
}
// (?) Overridden result builders in protocol hierarchies still contribute to
// ambiguities.
do {
protocol P1 {
@Builder<Int>
func function() -> Result
}
protocol P2: P1 {
@Builder<String>
func function() -> Result
}
protocol P3: P2 {
@Builder<Bool>
func function() -> Result
}
struct S: P3 {
// expected-note@+5{{add an explicit 'return' statement to not use a result builder}}{{+1:5-5=return <#expr#>\n}}
// expected-note@+4{{apply result builder 'Builder<Bool>' (inferred from protocol 'P3')}}{{5-5=@Builder<Bool> }}
// expected-note@+3{{apply result builder 'Builder<Int>' (inferred from protocol 'P1')}}{{5-5=@Builder<Int> }}
// expected-note@+2{{apply result builder 'Builder<String>' (inferred from protocol 'P2')}}{{5-5=@Builder<String> }}
// expected-error@+1{{ambiguous result builder inferred for 'function()': 'Builder<Bool>' or 'Builder<String>'}}
func function() -> Result {
}
}
}
//==============================================================================
// Inference suppression: explicit result builder.
//==============================================================================
struct Test7 {
@Builder<Int> dynamic func function() -> Result { 1 }
@Builder<Int>
dynamic var property1: Result { 1 }
dynamic var property2: Result { @Builder<Int> get { 1 } }
@Builder<Int>
dynamic subscript(subscript1 _: Int) -> Result { 1 }
dynamic subscript(subscript2 _: Int) -> Result { @Builder<Int> get { 1 } }
}
extension Test7 {
@Builder<Bool>
@_dynamicReplacement(for: function)
func replacement_function() -> Result { true }
@Builder<Bool>
@_dynamicReplacement(for: property1)
var replacement_property1: Result { true }
@_dynamicReplacement(for: property2)
var replacement_property2: Result {
@Builder<Bool> get { true }
}
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result {
@Builder<Bool> get { true }
}
@Builder<Bool>
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { true }
}
struct Test8: P_Builder_Int1 {
dynamic func function() -> Result { 1 }
dynamic var property1: Result { 1 }
dynamic var property2: Result { 1 }
dynamic subscript(subscript1 _: Int) -> Result { 1 }
dynamic subscript(subscript2 _: Int) -> Result { 1 }
}
extension Test8 {
@Builder<Bool>
@_dynamicReplacement(for: function)
func replacement_function() -> Result { true }
@Builder<Bool>
@_dynamicReplacement(for: property1)
var replacement_property1: Result { true }
@_dynamicReplacement(for: property2)
var replacement_property2: Result { @Builder<Bool> get { true } }
@Builder<Bool>
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { true }
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { @Builder<Bool> get { true } }
}
// Inference from dynamically replaced declaration is prioritized
// above inference from protocol requirements that are witnessed by it.
struct Test9: P_Builder_String {
@Builder<Int>
dynamic func function() -> Result { 1 }
@Builder<Int>
dynamic var property2: Result { 1 }
dynamic var property1: Result { @Builder<Int> get { 1 } }
@Builder<Int>
dynamic subscript(subscript1 _: Int) -> Result { 1 }
dynamic subscript(subscript2 _: Int) -> Result { @Builder<Int> get { 1 } }
}
extension Test9 {
@_dynamicReplacement(for: function)
func replacement_function() -> Result { 1 }
@_dynamicReplacement(for: property1)
var replacement_property1: Result { 1 }
@_dynamicReplacement(for: property2)
var replacement_property2: Result { 1 }
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { 1 }
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { 1 }
}
struct Test10: P_Builder_Int1, P_Builder_String {
@Builder<Int> dynamic func function() -> Result { 1 }
@Builder<Int>
dynamic var property1: Result { 1 }
dynamic var property2: Result { @Builder<Int> get { 1 } }
@Builder<Int>
dynamic subscript(subscript1 _: Int) -> Result { 1 }
dynamic subscript(subscript2 _: Int) -> Result { @Builder<Int> get { 1 } }
}
extension Test10 {
@Builder<Bool>
@_dynamicReplacement(for: function)
func replacement_function() -> Result { true }
@Builder<Bool>
@_dynamicReplacement(for: property1)
var replacement_property1: Result { true }
@_dynamicReplacement(for: property2)
var replacement_property2: Result { @Builder<Bool> get { true } }
@Builder<Bool>
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { true }
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { @Builder<Bool> get { true } }
}
//==============================================================================
// Inference suppression: return statements.
//==============================================================================
struct Test11 {
@Builder<Int>
dynamic func function() -> Result { 1 }
@Builder<Int>
dynamic var property1: Result { 1 }
dynamic var property2: Result { @Builder<Int> get { 1 } }
@Builder<Int>
dynamic subscript(subscript1 _: Int) -> Result { 1 }
dynamic subscript(subscript2 _: Int) -> Result { @Builder<Int> get { 1 } }
}
extension Test11 {
@_dynamicReplacement(for: function)
func replacement_function() -> Result {
do { if true { while true { return Result() } } }
}
@_dynamicReplacement(for: property2)
var replacement_property2: Result { return Result() }
@_dynamicReplacement(for: property1)
var replacement_property1: Result { get { return Result() } }
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { return Result() }
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { get { return Result() } }
}
struct Test12: P_Builder_Int1 {
dynamic func function() -> Result { 1 }
dynamic var property1: Result { 1 }
dynamic var property2: Result { 1 }
dynamic subscript(subscript1 _: Int) -> Result { 1 }
dynamic subscript(subscript2 _: Int) -> Result { 1 }
}
extension Test12 {
@_dynamicReplacement(for: function)
func replacement_function() -> Result { return Result() }
@_dynamicReplacement(for: property2)
var replacement_property2: Result { return Result() }
@_dynamicReplacement(for: property1)
var replacement_property1: Result { get { return Result() } }
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { return Result() }
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { get { return Result() } }
}
// Return statement in dynamically replaced declaration does not prevent the
// replacement from using it to infer a result builder.
struct Test13 {
// @expected-note@+1 {{remove the attribute to explicitly disable the result builder}}
@Builder<Int>
dynamic func function() -> Result {
return Result()
// @expected-warning@-1 {{application of result builder 'Builder<Int>' disabled by explicit 'return' statement}}
// @expected-note@-2 {{remove 'return' statements to apply the result builder}}
}
// @expected-note@+1 {{remove the attribute to explicitly disable the result builder}}
@Builder<Int>
dynamic var property1: Result {
return Result()
// @expected-warning@-1 {{application of result builder 'Builder<Int>' disabled by explicit 'return' statement}}
// @expected-note@-2 {{remove 'return' statements to apply the result builder}}
}
dynamic var property2: Result {
// @expected-note@+1 {{remove the attribute to explicitly disable the result builder}}
@Builder<Int>
get {
return Result()
// @expected-warning@-1 {{application of result builder 'Builder<Int>' disabled by explicit 'return' statement}}
// @expected-note@-2 {{remove 'return' statements to apply the result builder}}
}
}
// @expected-note@+1 {{remove the attribute to explicitly disable the result builder}}
@Builder<Int>
dynamic subscript(subscript1 _: Int) -> Result {
return Result()
// @expected-warning@-1 {{application of result builder 'Builder<Int>' disabled by explicit 'return' statement}}
// @expected-note@-2 {{remove 'return' statements to apply the result builder}}
}
dynamic subscript(subscript2 _: Int) -> Result {
// @expected-note@+1 {{remove the attribute to explicitly disable the result builder}}
@Builder<Int> get {
return Result()
// @expected-warning@-1 {{application of result builder 'Builder<Int>' disabled by explicit 'return' statement}}
// @expected-note@-2 {{remove 'return' statements to apply the result builder}}
}
}
}
extension Test13 {
@_dynamicReplacement(for: function)
func replacement_function() -> Result { 1 }
@_dynamicReplacement(for: property1)
var replacement_property1: Result { 1 }
@_dynamicReplacement(for: property2)
var replacement_property2: Result { 1 }
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { 1 }
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { 1 }
}
struct Test14: P_Builder_Int1 {
dynamic func function() -> Result { return Result() }
dynamic var property1: Result { return Result() }
dynamic var property2: Result { get { return Result() } }
dynamic subscript(subscript1 _: Int) -> Result { return Result() }
dynamic subscript(subscript2 _: Int) -> Result { get { return Result() } }
}
extension Test14 {
@_dynamicReplacement(for: function)
func replacement_function() -> Result { 1 }
@_dynamicReplacement(for: property1)
var replacement_property1: Result { 1 }
@_dynamicReplacement(for: property2)
var replacement_property2: Result { 1 }
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { 1 }
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { 1 }
}
struct Test15: P_Builder_Int1, P_Builder_String {
dynamic func function() -> Result { return Result() }
dynamic var property1: Result { return Result() }
dynamic var property2: Result { get { return Result() } }
dynamic subscript(subscript1 _: Int) -> Result { return Result() }
dynamic subscript(subscript2 _: Int) -> Result { get { return Result() } }
}
extension Test15 {
@_dynamicReplacement(for: function)
func replacement_function() -> Result { return Result() }
@_dynamicReplacement(for: property2)
var replacement_property2: Result { return Result() }
@_dynamicReplacement(for: property1)
var replacement_property1: Result { get { return Result() } }
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { return Result() }
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { get { return Result() } }
}
//==============================================================================
// Inference suppression: separation of conformance context & witness context.
// Only conformances declared on the witness context are considered in
// inference from protocol requirements.
//==============================================================================
struct Test16 {
dynamic func function() -> Result { Result() }
dynamic var property1: Result { Result() }
dynamic var property2: Result { Result() }
dynamic subscript(subscript1 _: Int) -> Result { Result() }
dynamic subscript(subscript2 _: Int) -> Result { Result() }
}
extension Test16: P_Builder_Int1 {
@_dynamicReplacement(for: function)
func replacement_function() -> Result { Result() }
@_dynamicReplacement(for: property1)
var replacement_property1: Result { Result() }
@_dynamicReplacement(for: property2)
var replacement_property2: Result { Result() }
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { Result() }
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { Result() }
}
struct Test17 {
dynamic func function() -> Result { Result() }
}
extension Test17: P_Builder_Int1 {
@_dynamicReplacement(for: function)
func replacement_function() -> Result { Result() }
dynamic var property1: Result { 1 }
}
extension Test17: P_Builder_String {
@_dynamicReplacement(for: property1)
var replacement_property1: Result { 1 }
dynamic var property2: Result { "1" }
}
extension Test17: P_Builder_Bool {
@_dynamicReplacement(for: property2)
var replacement_property2: Result { "1" }
dynamic subscript(subscript1 _: Int) -> Result { true }
}
extension Test17: P_Builder_Int2 {
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { true }
dynamic subscript(subscript2 _: Int) -> Result { 1 }
}
extension Test17 {
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { 1 }
}
struct Test18: P_Builder_Int1, P_Builder_String, P_Builder_Bool {}
extension Test18 {
dynamic func function() -> Result { Result() }
dynamic var property1: Result { Result() }
dynamic var property2: Result { Result() }
dynamic subscript(subscript1 _: Int) -> Result { Result() }
dynamic subscript(subscript2 _: Int) -> Result { Result() }
@_dynamicReplacement(for: function)
func replacement_function() -> Result { Result() }
@_dynamicReplacement(for: property1)
var replacement_property1: Result { Result() }
@_dynamicReplacement(for: property2)
var replacement_property2: Result { Result() }
@_dynamicReplacement(for: subscript(subscript1:))
subscript(replacement_subscript1 _: Int) -> Result { Result() }
@_dynamicReplacement(for: subscript(subscript2:))
subscript(replacement_subscript2 _: Int) -> Result { Result() }
}
|