mirror of
https://github.com/apple/swift.git
synced 2025-12-21 12:14:44 +01:00
Since we infer unsafety from a use of a declaration that involves unsafe types in its signature, there isn't a reason to require @unsafe on declaration to restate it. This matches recent revisions of SE-0458.
43 lines
1.8 KiB
Swift
43 lines
1.8 KiB
Swift
// RUN: %empty-directory(%t)
|
|
// RUN: %target-swift-frontend -emit-module-path %t/unsafe_swift_decls.swiftmodule %S/Inputs/unsafe_swift_decls.swift -enable-experimental-feature AllowUnsafeAttribute
|
|
|
|
// RUN: %target-typecheck-verify-swift -enable-experimental-feature AllowUnsafeAttribute -enable-experimental-feature WarnUnsafe -I %S/Inputs -I %t
|
|
|
|
// REQUIRES: swift_feature_AllowUnsafeAttribute
|
|
// REQUIRES: swift_feature_WarnUnsafe
|
|
|
|
import unsafe_decls
|
|
import unsafe_swift_decls
|
|
|
|
func testUnsafe(_ ut: UnsafeType) {
|
|
// expected-warning@+1{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{3-3=unsafe }}
|
|
unsafe_c_function() // expected-note{{reference to unsafe global function 'unsafe_c_function()'}}
|
|
|
|
var array: [CInt] = [1, 2, 3, 4, 5]
|
|
// expected-warning@+1{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{3-3=unsafe }}
|
|
print_ints(&array, CInt(array.count))
|
|
// expected-note@-1{{reference to global function 'print_ints' involves unsafe type 'UnsafeMutablePointer<Int32>'}}
|
|
}
|
|
|
|
// Reference a typealias that isn't itself @unsafe, but refers to an unsafe
|
|
// type.
|
|
|
|
func testUnsafeThroughAlias(_ ut: UnsafeTypeAlias) {
|
|
|
|
}
|
|
|
|
func callThroughAlias(ut: UnsafeTypeAlias) {
|
|
// expected-warning@+1{{expression uses unsafe constructs but is not marked with 'unsafe'}}
|
|
testUnsafeThroughAlias(ut) // expected-note{{reference to global function 'testUnsafeThroughAlias' involves unsafe type 'UnsafeTypeAlias' (aka 'PointerType')}}
|
|
// expected-note@-1{{reference to parameter 'ut' involves unsafe type 'UnsafeTypeAlias' (aka 'PointerType')}}
|
|
}
|
|
|
|
|
|
struct ConformsToUnsafeRequirement: HasUnsafeRequirement {
|
|
@unsafe func f(_: PointerType) { }
|
|
}
|
|
|
|
class SubclassWithUnsafeMethod: SuperclassWithUnsafeMethod {
|
|
@unsafe override func implicitlyUnsafe(_: PointerType) { }
|
|
}
|