Improve diagnostic for unsafe call arguments

Use the argument type rather than the (potentially generic) parameter type.
This commit is contained in:
Doug Gregor
2025-05-21 13:30:43 +01:00
parent d4dc36d2f3
commit d5476aeda0
4 changed files with 7 additions and 7 deletions

View File

@@ -165,20 +165,20 @@ void swift::diagnoseUnsafeUse(const UnsafeUse &use) {
ctx.Diags.diagnose(
loc,
diag::note_unsafe_call_decl_argument_indexed,
calleeDecl, argumentIndex, paramType)
calleeDecl, argumentIndex, argument->getType())
.highlight(argument->getSourceRange());
} else {
ctx.Diags.diagnose(
loc,
diag::note_unsafe_call_decl_argument_named,
calleeDecl, argumentName, paramType)
calleeDecl, argumentName, argument->getType())
.highlight(argument->getSourceRange());
}
} else {
ctx.Diags.diagnose(
loc,
diag::note_unsafe_call_argument_indexed,
argumentIndex, paramType)
argumentIndex, argument->getType())
.highlight(argument->getSourceRange());
}

View File

@@ -334,8 +334,8 @@ func testSwitch(se: SomeEnum) {
switch unsafe se {
case someEnumValue: break
// expected-warning@-1{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{8-8=unsafe }}
// expected-note@-2{{argument #0 in call to operator function '~=' has unsafe type 'T'}}
// expected-note@-3{{argument #1 in call to operator function '~=' has unsafe type 'T'}}
// expected-note@-2{{argument #0 in call to operator function '~=' has unsafe type 'SomeEnum'}}
// expected-note@-3{{argument #1 in call to operator function '~=' has unsafe type 'SomeEnum'}}
// expected-note@-4{{reference to unsafe type 'SomeEnum'}}
// expected-note@-5{{reference to unsafe var 'someEnumValue'}}
// expected-note@-6{{reference to let '$match' involves unsafe type 'SomeEnum'}}

View File

@@ -49,7 +49,7 @@ extension ConformsToMultiP: MultiP {
// expected-note@-1{{unsafe type 'UnsafeSuper' cannot satisfy safe associated type 'Ptr'}}
@unsafe func f() -> UnsafeSuper {
.init() // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe'}}
// expected-note@-1{{argument 'self' in call to initializer 'init' has unsafe type 'UnsafeSuper'}}
// expected-note@-1{{argument 'self' in call to initializer 'init' has unsafe type 'UnsafeSuper.Type'}}
}
}

View File

@@ -9,7 +9,7 @@ func test(
) {
var array = [1, 2, 3]
// expected-warning@+2{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{3-3=unsafe }}
// expected-note@+1{{argument #0 in call to instance method 'withUnsafeBufferPointer' has unsafe type '(UnsafeBufferPointer<Element>) throws(E) -> R'}}
// expected-note@+1{{argument #0 in call to instance method 'withUnsafeBufferPointer' has unsafe type '(UnsafeBufferPointer<Int>) -> ()'}}
array.withUnsafeBufferPointer{ buffer in
// expected-warning@+1{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{5-5=unsafe }}
print(buffer) // expected-note{{reference to parameter 'buffer' involves unsafe type 'UnsafeBufferPointer<Int>'}}