mirror of
https://github.com/apple/swift.git
synced 2025-12-14 20:36:38 +01:00
- Don't attempt to insert fixes if there are restrictions present, they'd inform the failures. Inserting fixes too early doesn't help the solver because restriction matching logic would record the same fixes. - Adjust impact of the fixes. Optional conversions shouldn't impact the score in any way because they are not the source of the issue. - Look through one level of optional when failure is related to optional injection. The diagnostic is going to be about underlying type, so there is no reason to print optional on right-hand side.
74 lines
4.0 KiB
Swift
74 lines
4.0 KiB
Swift
// RUN: %empty-directory(%t)
|
|
|
|
// RUN: %gyb -DOPT_KIND=None %s -o %t/pointer_conversion.swift
|
|
// RUN: %line-directive %t/pointer_conversion.swift -- %target-swift-frontend -typecheck -verify %t/pointer_conversion.swift
|
|
|
|
// RUN: %gyb -DOPT_KIND=Optional %s -o %t/pointer_conversion_opt.swift
|
|
// RUN: %line-directive %t/pointer_conversion_opt.swift -- %target-swift-frontend -typecheck -verify %t/pointer_conversion_opt.swift
|
|
|
|
// RUN: %gyb -DOPT_KIND=ImplicitlyUnwrappedOptional %s -o %t/pointer_conversion_iuo.swift
|
|
// RUN: %line-directive %t/pointer_conversion_iuo.swift -- %target-swift-frontend -typecheck -verify %t/pointer_conversion_iuo.swift
|
|
|
|
// REQUIRES: objc_interop
|
|
|
|
%{
|
|
if OPT_KIND == 'Optional':
|
|
suffix='?'
|
|
elif OPT_KIND == 'ImplicitlyUnwrappedOptional':
|
|
suffix='!'
|
|
else:
|
|
suffix=''
|
|
}%
|
|
|
|
class C {}
|
|
class D {}
|
|
|
|
func takesMutablePointer(_ x: UnsafeMutablePointer<Int>${suffix}) {}
|
|
func takesMutableVoidPointer(_ x: UnsafeMutableRawPointer${suffix}) {}
|
|
@discardableResult
|
|
func takesConstPointer(_ x: UnsafePointer<Int>${suffix}) -> Character { return "x" }
|
|
func takesConstVoidPointer(_ x: UnsafeRawPointer${suffix}) {}
|
|
|
|
func takesAutoreleasingPointer(_ x: AutoreleasingUnsafeMutablePointer<C>${suffix}) {}
|
|
|
|
func pointerArgumentsObjC(ap: AutoreleasingUnsafeMutablePointer<Int>,
|
|
afp: AutoreleasingUnsafeMutablePointer<Float>) {
|
|
takesMutablePointer(ap) // expected-error{{cannot convert value of type 'AutoreleasingUnsafeMutablePointer<Int>' to expected argument type 'UnsafeMutablePointer<Int>'}}
|
|
takesMutableVoidPointer(ap) // expected-error{{cannot convert value of type 'AutoreleasingUnsafeMutablePointer<Int>' to expected argument type 'UnsafeMutableRawPointer'}}
|
|
takesConstPointer(ap)
|
|
takesConstVoidPointer(ap)
|
|
takesConstVoidPointer(afp)
|
|
|
|
var x: UnsafeRawPointer
|
|
x = ap // expected-error{{cannot assign value of type 'AutoreleasingUnsafeMutablePointer<Int>' to type 'UnsafeRawPointer'}}
|
|
_ = x
|
|
}
|
|
|
|
func autoreleasingPointerArguments(p: UnsafeMutablePointer<Int>,
|
|
cp: UnsafePointer<Int>,
|
|
ap: AutoreleasingUnsafeMutablePointer<C>) {
|
|
takesAutoreleasingPointer(nil)
|
|
% if not suffix:
|
|
// expected-error@-2 {{'nil' is not compatible with expected argument type}}
|
|
% end
|
|
|
|
takesAutoreleasingPointer(p) // expected-error{{cannot convert value of type 'UnsafeMutablePointer<Int>' to expected argument type 'AutoreleasingUnsafeMutablePointer<C>'}}
|
|
takesAutoreleasingPointer(cp) // expected-error{{cannot convert value of type 'UnsafePointer<Int>' to expected argument type 'AutoreleasingUnsafeMutablePointer<C>'}}
|
|
takesAutoreleasingPointer(ap)
|
|
|
|
var c: C = C()
|
|
takesAutoreleasingPointer(&c)
|
|
takesAutoreleasingPointer(c) // expected-error{{cannot convert value of type 'C' to expected argument type 'AutoreleasingUnsafeMutablePointer<C>'}}
|
|
var d: D = D()
|
|
takesAutoreleasingPointer(&d) // expected-error{{cannot convert value of type 'AutoreleasingUnsafeMutablePointer<D>' to expected argument type 'AutoreleasingUnsafeMutablePointer<C>'}}
|
|
// expected-note@-1 {{arguments to generic parameter 'Pointee' ('D' and 'C') are expected to be equal}}
|
|
takesAutoreleasingPointer(d) // expected-error{{cannot convert value of type 'D' to expected argument type 'AutoreleasingUnsafeMutablePointer<C>'}}
|
|
var cc: [C] = [C(), C()]
|
|
var dd: [D] = [D(), D()]
|
|
takesAutoreleasingPointer(&cc) // expected-error{{cannot convert value of type 'AutoreleasingUnsafeMutablePointer<[C]>' to expected argument type 'AutoreleasingUnsafeMutablePointer<C>'}}
|
|
// expected-note@-1 {{arguments to generic parameter 'Pointee' ('[C]' and 'C') are expected to be equal}}
|
|
takesAutoreleasingPointer(&dd) // expected-error{{cannot convert value of type 'AutoreleasingUnsafeMutablePointer<[D]>' to expected argument type 'AutoreleasingUnsafeMutablePointer<C>'}}
|
|
// expected-note@-1 {{arguments to generic parameter 'Pointee' ('[D]' and 'C') are expected to be equal}}
|
|
let _: AutoreleasingUnsafeMutablePointer<C> = &c // expected-error {{'&' may only be used to pass an argument to inout parameter}}
|
|
}
|