Skip to content

Commit 6ca7e38

Browse files
[tests] Add more test cases for SR-12019 dynamic callable
1 parent f796e27 commit 6ca7e38

File tree

2 files changed

+26
-3
lines changed

2 files changed

+26
-3
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4259,7 +4259,7 @@ static bool checkForDynamicAttribute(CanType ty,
42594259
}
42604260

42614261
// Otherwise, this must be a nominal type.
4262-
// Neither Dynamic member lookup or Dynamic Callable doesn't
4262+
// Neither Dynamic member lookup nor Dynamic Callable doesn't
42634263
// work for tuples, etc.
42644264
auto nominal = ty->getAnyNominal();
42654265
if (!nominal)

test/attr/attr_dynamic_callable.swift

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -490,11 +490,34 @@ B()("\(1)") // ok
490490

491491
// SR-12019
492492
@dynamicCallable
493-
struct SR12019 {
493+
struct SR12019_S {
494494
func dynamicallyCall<T: StringProtocol>(withArguments: [T]) { // expected-note {{where 'T' = 'Int'}}
495495
print("hi")
496496
}
497497
}
498498

499-
let sr12019 = SR12019()
499+
@dynamicCallable
500+
protocol SR12019 {
501+
func dynamicallyCall<T: StringProtocol>(withArguments: [T]) // expected-note 2{{where 'T' = 'Int'}}
502+
}
503+
504+
class SR12019Class: SR12019 {
505+
func dynamicallyCall<T: StringProtocol>(withArguments: [T]) {} // expected-note {{where 'T' = 'Int'}}
506+
}
507+
508+
class SR12019SubClass: SR12019Class {}
509+
510+
let sr12019s = SR12019_S()
511+
sr12019s(1) // expected-error {{instance method 'dynamicallyCall(withArguments:)' requires that 'Int' conform to 'StringProtocol'}}
512+
513+
// Protocol composition
514+
let sr12019: SR12019&AnyObject = SR12019Class()
500515
sr12019(1) // expected-error {{instance method 'dynamicallyCall(withArguments:)' requires that 'Int' conform to 'StringProtocol'}}
516+
517+
// Protocol
518+
let sr12019c: SR12019 = SR12019Class()
519+
sr12019c(1) // expected-error {{instance method 'dynamicallyCall(withArguments:)' requires that 'Int' conform to 'StringProtocol'}}
520+
521+
// Subclass
522+
let sr12019sub = SR12019SubClass()
523+
sr12019sub(1) // expected-error {{instance method 'dynamicallyCall(withArguments:)' requires that 'Int' conform to 'StringProtocol'}}

0 commit comments

Comments
 (0)