Skip to content

Commit d794c95

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

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
@@ -168,20 +168,20 @@ void swift::diagnoseUnsafeUse(const UnsafeUse &use) {
168168
ctx.Diags.diagnose(
169169
loc,
170170
diag::note_unsafe_call_decl_argument_indexed,
171-
calleeDecl, argumentIndex, paramType)
171+
calleeDecl, argumentIndex, argument->getType())
172172
.highlight(argument->getSourceRange());
173173
} else {
174174
ctx.Diags.diagnose(
175175
loc,
176176
diag::note_unsafe_call_decl_argument_named,
177-
calleeDecl, argumentName, paramType)
177+
calleeDecl, argumentName, argument->getType())
178178
.highlight(argument->getSourceRange());
179179
}
180180
} else {
181181
ctx.Diags.diagnose(
182182
loc,
183183
diag::note_unsafe_call_argument_indexed,
184-
argumentIndex, paramType)
184+
argumentIndex, argument->getType())
185185
.highlight(argument->getSourceRange());
186186
}
187187

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)