Skip to content

Commit 4a9b30a

Browse files
committed
[test] Add test for dynamic member lookup behaviour changed by #15412
1 parent be88499 commit 4a9b30a

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed

test/Constraints/dynamic_lookup.swift

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -336,3 +336,51 @@ func testOverloadedWithUnavailable(ao: AnyObject) {
336336
ao.overloadedWithUnavailableB()
337337
}
338338

339+
// Test that we correctly diagnose ambiguity for different typed members available
340+
// through dynamic lookup.
341+
@objc protocol P3 {
342+
var ambiguousProperty: String { get } // expected-note {{found this candidate}}
343+
var unambiguousProperty: Int { get }
344+
345+
func ambiguousMethod() -> String // expected-note 2{{found this candidate}}
346+
func unambiguousMethod() -> Int
347+
348+
func ambiguousMethodParam(_ x: String) // expected-note {{found this candidate}}
349+
func unambiguousMethodParam(_ x: Int)
350+
351+
subscript(ambiguousSubscript _: Int) -> String { get } // expected-note {{found this candidate}}
352+
subscript(unambiguousSubscript _: String) -> Int { get } // expected-note {{found this candidate}}
353+
}
354+
355+
class C1 {
356+
@objc var ambiguousProperty: Int { return 0 } // expected-note {{found this candidate}}
357+
@objc var unambiguousProperty: Int { return 0 }
358+
359+
@objc func ambiguousMethod() -> Int { return 0 } // expected-note 2{{found this candidate}}
360+
@objc func unambiguousMethod() -> Int { return 0 }
361+
362+
@objc func ambiguousMethodParam(_ x: Int) {} // expected-note {{found this candidate}}
363+
@objc func unambiguousMethodParam(_ x: Int) {}
364+
365+
@objc subscript(ambiguousSubscript _: Int) -> Int { return 0 } // expected-note {{found this candidate}}
366+
@objc subscript(unambiguousSubscript _: String) -> Int { return 0 } // expected-note {{found this candidate}}
367+
}
368+
369+
func testAnyObjectAmbiguity(_ x: AnyObject) {
370+
_ = x.ambiguousProperty // expected-error {{ambiguous use of 'ambiguousProperty'}}
371+
_ = x.unambiguousProperty
372+
373+
_ = x.ambiguousMethod() // expected-error {{ambiguous use of 'ambiguousMethod()'}}
374+
_ = x.unambiguousMethod()
375+
376+
_ = x.ambiguousMethod // expected-error {{ambiguous use of 'ambiguousMethod()'}}
377+
_ = x.unambiguousMethod
378+
379+
_ = x.ambiguousMethodParam // expected-error {{ambiguous use of 'ambiguousMethodParam'}}
380+
_ = x.unambiguousMethodParam
381+
382+
_ = x[ambiguousSubscript: 0] // expected-error {{ambiguous use of 'subscript(ambiguousSubscript:)'}}
383+
384+
// FIX-ME(SR-8611): This is currently ambiguous but shouldn't be.
385+
_ = x[unambiguousSubscript: ""] // expected-error {{ambiguous use of 'subscript(unambiguousSubscript:)'}}
386+
}

0 commit comments

Comments
 (0)