|
| 1 | +// RUN: %target-swift-emit-silgen %s | %FileCheck %s |
| 2 | + |
| 3 | +// rdar://156454697 |
| 4 | + |
| 5 | +// The appearance of DynamicSelfType as an argument type to == |
| 6 | +// would lead us to choose the Base.== overload, which is less |
| 7 | +// "specific" than Derived.==. There was a similar bug with |
| 8 | +// archetypes. |
| 9 | +// |
| 10 | +// This is a SILGen test, to check the overload choice. |
| 11 | + |
| 12 | +public class Base: Equatable { |
| 13 | + public static func ==(lhs: Base, rhs: Base) -> Bool { |
| 14 | + return false |
| 15 | + } |
| 16 | +} |
| 17 | + |
| 18 | +public class Derived: Base { |
| 19 | + // CHECK-LABEL: sil [ossa] @$s32subclass_shadows_operator_equals7DerivedC2f1SbyF : $@convention(method) (@guaranteed Derived) -> Bool { |
| 20 | + // CHECK: function_ref @$s32subclass_shadows_operator_equals7DerivedC2eeoiySbAC_ACtFZ : $@convention(method) (@guaranteed Derived, @guaranteed Derived, @thick Derived.Type) -> Bool |
| 21 | + // CHECK: return |
| 22 | + public func f1() -> Bool { |
| 23 | + return self == self |
| 24 | + } |
| 25 | + |
| 26 | + // CHECK-LABEL: sil [ossa] @$s32subclass_shadows_operator_equals7DerivedC2f2SbyF : $@convention(method) (@guaranteed Derived) -> Bool { |
| 27 | + // CHECK: function_ref @$s32subclass_shadows_operator_equals7DerivedC2eeoiySbAC_ACtFZ : $@convention(method) (@guaranteed Derived, @guaranteed Derived, @thick Derived.Type) -> Bool |
| 28 | + // CHECK: return |
| 29 | + public func f2() -> Bool { |
| 30 | + let c = self as! Self |
| 31 | + return self == c |
| 32 | + } |
| 33 | + |
| 34 | + // CHECK-LABEL: sil [ossa] @$s32subclass_shadows_operator_equals7DerivedC2f3SbyF : $@convention(method) (@guaranteed Derived) -> Bool { |
| 35 | + // CHECK: function_ref @$s32subclass_shadows_operator_equals7DerivedC2eeoiySbAC_ACtFZ : $@convention(method) (@guaranteed Derived, @guaranteed Derived, @thick Derived.Type) -> Bool |
| 36 | + // CHECK: return |
| 37 | + public func f3() -> Bool { |
| 38 | + let c = self as! Self |
| 39 | + return c == self |
| 40 | + } |
| 41 | + |
| 42 | + // CHECK-LABEL: sil [ossa] @$s32subclass_shadows_operator_equals7DerivedC2f4SbyF : $@convention(method) (@guaranteed Derived) -> Bool { |
| 43 | + // CHECK: function_ref @$s32subclass_shadows_operator_equals7DerivedC2eeoiySbAC_ACtFZ : $@convention(method) (@guaranteed Derived, @guaranteed Derived, @thick Derived.Type) -> Bool |
| 44 | + // CHECK: return |
| 45 | + public func f4() -> Bool { |
| 46 | + let c = self as! Self |
| 47 | + return c == c |
| 48 | + } |
| 49 | + |
| 50 | + // CHECK-LABEL: sil [ossa] @$s32subclass_shadows_operator_equals7DerivedC2g1ySbxACRbzlF : $@convention(method) <T where T : Derived> (@guaranteed T, @guaranteed Derived) -> Bool { |
| 51 | + // CHECK: function_ref @$s32subclass_shadows_operator_equals7DerivedC2eeoiySbAC_ACtFZ : $@convention(method) (@guaranteed Derived, @guaranteed Derived, @thick Derived.Type) -> Bool |
| 52 | + // CHECK: return |
| 53 | + public func g1<T: Derived>(_ c: T) -> Bool { |
| 54 | + return self == c |
| 55 | + } |
| 56 | + |
| 57 | + // CHECK-LABEL: sil [ossa] @$s32subclass_shadows_operator_equals7DerivedC2g2ySbxACRbzlF : $@convention(method) <T where T : Derived> (@guaranteed T, @guaranteed Derived) -> Bool { |
| 58 | + // CHECK: function_ref @$s32subclass_shadows_operator_equals7DerivedC2eeoiySbAC_ACtFZ : $@convention(method) (@guaranteed Derived, @guaranteed Derived, @thick Derived.Type) -> Bool |
| 59 | + // CHECK: return |
| 60 | + public func g2<T: Derived>(_ c: T) -> Bool { |
| 61 | + return c == self |
| 62 | + } |
| 63 | + |
| 64 | + // CHECK-LABEL: sil [ossa] @$s32subclass_shadows_operator_equals7DerivedC2g3ySbxACRbzlF : $@convention(method) <T where T : Derived> (@guaranteed T, @guaranteed Derived) -> Bool { |
| 65 | + // CHECK: function_ref @$s32subclass_shadows_operator_equals7DerivedC2eeoiySbAC_ACtFZ : $@convention(method) (@guaranteed Derived, @guaranteed Derived, @thick Derived.Type) -> Bool |
| 66 | + // CHECK: return |
| 67 | + public func g3<T: Derived>(_ c: T) -> Bool { |
| 68 | + return c == c |
| 69 | + } |
| 70 | + |
| 71 | + public static func ==(lhs: Derived, rhs: Derived) -> Bool { |
| 72 | + return false |
| 73 | + } |
| 74 | +} |
0 commit comments