Skip to content

Commit d5476ae

Browse files
committed
Improve diagnostic for unsafe call arguments
Use the argument type rather than the (potentially generic) parameter type.
1 parent d4dc36d commit d5476ae

File tree

4 files changed

+7
-7
lines changed

4 files changed

+7
-7
lines changed

lib/Sema/TypeCheckUnsafe.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,20 @@ void swift::diagnoseUnsafeUse(const UnsafeUse &use) {
165165
ctx.Diags.diagnose(
166166
loc,
167167
diag::note_unsafe_call_decl_argument_indexed,
168-
calleeDecl, argumentIndex, paramType)
168+
calleeDecl, argumentIndex, argument->getType())
169169
.highlight(argument->getSourceRange());
170170
} else {
171171
ctx.Diags.diagnose(
172172
loc,
173173
diag::note_unsafe_call_decl_argument_named,
174-
calleeDecl, argumentName, paramType)
174+
calleeDecl, argumentName, argument->getType())
175175
.highlight(argument->getSourceRange());
176176
}
177177
} else {
178178
ctx.Diags.diagnose(
179179
loc,
180180
diag::note_unsafe_call_argument_indexed,
181-
argumentIndex, paramType)
181+
argumentIndex, argument->getType())
182182
.highlight(argument->getSourceRange());
183183
}
184184

test/Unsafe/safe.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,8 @@ func testSwitch(se: SomeEnum) {
334334
switch unsafe se {
335335
case someEnumValue: break
336336
// expected-warning@-1{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{8-8=unsafe }}
337-
// expected-note@-2{{argument #0 in call to operator function '~=' has unsafe type 'T'}}
338-
// expected-note@-3{{argument #1 in call to operator function '~=' has unsafe type 'T'}}
337+
// expected-note@-2{{argument #0 in call to operator function '~=' has unsafe type 'SomeEnum'}}
338+
// expected-note@-3{{argument #1 in call to operator function '~=' has unsafe type 'SomeEnum'}}
339339
// expected-note@-4{{reference to unsafe type 'SomeEnum'}}
340340
// expected-note@-5{{reference to unsafe var 'someEnumValue'}}
341341
// expected-note@-6{{reference to let '$match' involves unsafe type 'SomeEnum'}}

test/Unsafe/unsafe.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ extension ConformsToMultiP: MultiP {
4949
// expected-note@-1{{unsafe type 'UnsafeSuper' cannot satisfy safe associated type 'Ptr'}}
5050
@unsafe func f() -> UnsafeSuper {
5151
.init() // expected-warning{{expression uses unsafe constructs but is not marked with 'unsafe'}}
52-
// expected-note@-1{{argument 'self' in call to initializer 'init' has unsafe type 'UnsafeSuper'}}
52+
// expected-note@-1{{argument 'self' in call to initializer 'init' has unsafe type 'UnsafeSuper.Type'}}
5353
}
5454
}
5555

test/Unsafe/unsafe_stdlib.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ func test(
99
) {
1010
var array = [1, 2, 3]
1111
// expected-warning@+2{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{3-3=unsafe }}
12-
// expected-note@+1{{argument #0 in call to instance method 'withUnsafeBufferPointer' has unsafe type '(UnsafeBufferPointer<Element>) throws(E) -> R'}}
12+
// expected-note@+1{{argument #0 in call to instance method 'withUnsafeBufferPointer' has unsafe type '(UnsafeBufferPointer<Int>) -> ()'}}
1313
array.withUnsafeBufferPointer{ buffer in
1414
// expected-warning@+1{{expression uses unsafe constructs but is not marked with 'unsafe'}}{{5-5=unsafe }}
1515
print(buffer) // expected-note{{reference to parameter 'buffer' involves unsafe type 'UnsafeBufferPointer<Int>'}}

0 commit comments

Comments
 (0)