mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
49 lines
1.7 KiB
Swift
49 lines
1.7 KiB
Swift
// RUN: %target-swift-frontend -emit-silgen -enable-sil-ownership %s | %FileCheck %s
|
|
|
|
class TestClass {
|
|
|
|
final
|
|
var finalProperty : Int { return 42 }
|
|
|
|
final
|
|
func finalMethod() -> Int { return 12 }
|
|
|
|
|
|
func baseMethod() {}
|
|
}
|
|
|
|
class TestDerived : TestClass {
|
|
final
|
|
override func baseMethod() {}
|
|
}
|
|
|
|
|
|
// CHECK-LABEL: sil hidden @{{.*}}testDirectDispatch{{.*}} : $@convention(thin) (@owned TestClass) -> Int {
|
|
// CHECK: bb0([[ARG:%.*]] : @owned $TestClass):
|
|
// CHECK: [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
|
|
// CHECK: [[FINALMETH:%[0-9]+]] = function_ref @_T05final9TestClassC0A6Method{{[_0-9a-zA-Z]*}}F
|
|
// CHECK: apply [[FINALMETH]]([[BORROWED_ARG]])
|
|
// CHECK: end_borrow [[BORROWED_ARG]] from [[ARG]]
|
|
// CHECK: [[BORROWED_ARG:%.*]] = begin_borrow [[ARG]]
|
|
// CHECK: [[FINALPROP:%[0-9]+]] = function_ref @_T05final9TestClassC0A8PropertySivg
|
|
// CHECK: apply [[FINALPROP]]([[BORROWED_ARG]])
|
|
// CHECK: end_borrow [[BORROWED_ARG]] from [[ARG]]
|
|
func testDirectDispatch(c : TestClass) -> Int {
|
|
return c.finalMethod()+c.finalProperty
|
|
}
|
|
|
|
|
|
// Verify that the non-overriding final methods don't get emitted to the vtable.
|
|
// CHECK-LABEL: sil_vtable TestClass {
|
|
// CHECK-NEXT: #TestClass.baseMethod!1: {{.*}} : _T05final9TestClassC10baseMethod{{[_0-9a-zA-Z]*}}F
|
|
// CHECK-NEXT: #TestClass.init!initializer.1: {{.*}} : _T05final9TestClassC{{[_0-9a-zA-Z]*}}fc
|
|
// CHECK-NEXT: #TestClass.deinit!
|
|
// CHECK-NEXT: }
|
|
|
|
// Verify that overriding final methods don't get emitted to the vtable.
|
|
// CHECK-LABEL: sil_vtable TestDerived {
|
|
// CHECK-NEXT: #TestClass.baseMethod!1: {{.*}} : _T05final11TestDerivedC10baseMethod{{[_0-9a-zA-Z]*}}F
|
|
// CHECK-NEXT: #TestClass.init!initializer.1: {{.*}} : _T05final11TestDerivedC{{[_0-9a-zA-Z]*}}fc
|
|
// CHECK-NEXT: #TestDerived.deinit!
|
|
// CHECK-NEXT: }
|