Skip to content

Commit 14b70f3

Browse files
committed
DiagnosticVerifier: Default expected fix-it start line to the diagnostic's
1 parent 8306f87 commit 14b70f3

38 files changed

+214
-197
lines changed

lib/Frontend/DiagnosticVerifier.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,8 @@ static Optional<LineColumnRange> parseExpectedFixItRange(
447447

448448
if (const auto lineAndCol = parseLineAndColumn()) {
449449
std::tie(Range.StartLine, Range.StartCol) = lineAndCol.value();
450+
if (Range.StartLine == LineColumnRange::NoValue)
451+
Range.StartLine = DiagnosticLineNo;
450452
} else {
451453
return None;
452454
}

test/AutoDiff/SILOptimizer/differentiation_control_flow_diagnostics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,9 +168,9 @@ enum Tree : Differentiable & AdditiveArithmetic {
168168
// (`Collection.makeIterator` and `IteratorProtocol.next`).
169169
// expected-error @+1 {{function is not differentiable}}
170170
@differentiable(reverse)
171-
// expected-note @+1 {{when differentiating this function definition}}
171+
// expected-note @+2 {{when differentiating this function definition}}
172+
// expected-note @+1 {{cannot differentiate through a non-differentiable result; do you want to use 'withoutDerivative(at:)'?}} {{+2:12-12=withoutDerivative(at: }} {{+2:17-17=)}}
172173
func loop_array(_ array: [Float]) -> Float {
173-
// expected-note @-1 {{cannot differentiate through a non-differentiable result; do you want to use 'withoutDerivative(at:)'?}} {{12-12=withoutDerivative(at: }} {{17-17=)}}
174174
var result: Float = 1
175175
for x in array {
176176
result = result * x

test/AutoDiff/Sema/derivative_attr_type_checking.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,16 +1105,16 @@ fileprivate func _private_original_fileprivate_derivative(_ x: Float) -> (value:
11051105
public func public_original_private_derivative(_ x: Float) -> Float { x }
11061106
// expected-error @+1 {{derivative function must have same access level as original function; derivative function '_public_original_private_derivative' is fileprivate, but original function 'public_original_private_derivative' is public}}
11071107
@derivative(of: public_original_private_derivative)
1108-
// expected-note @+1 {{mark the derivative function as '@usableFromInline' to match the original function}} {{1-1=@usableFromInline }}
11091108
fileprivate func _public_original_private_derivative(_ x: Float) -> (value: Float, pullback: (Float) -> Float) {
1109+
// expected-note @-1 {{mark the derivative function as '@usableFromInline' to match the original function}} {{-1:1-1=@usableFromInline }}
11101110
fatalError()
11111111
}
11121112

11131113
public func public_original_internal_derivative(_ x: Float) -> Float { x }
11141114
// expected-error @+1 {{derivative function must have same access level as original function; derivative function '_public_original_internal_derivative' is internal, but original function 'public_original_internal_derivative' is public}}
11151115
@derivative(of: public_original_internal_derivative)
1116-
// expected-note @+1 {{mark the derivative function as '@usableFromInline' to match the original function}} {{1-1=@usableFromInline }}
11171116
func _public_original_internal_derivative(_ x: Float) -> (value: Float, pullback: (Float) -> Float) {
1117+
// expected-note @-1 {{mark the derivative function as '@usableFromInline' to match the original function}} {{-1:1-1=@usableFromInline }}
11181118
fatalError()
11191119
}
11201120

test/Concurrency/async_initializer.swift

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ protocol AsyncDefaultConstructable {
139139
init() async
140140
}
141141

142-
protocol DefaultConstructable {
143-
init() // expected-note {{protocol requires initializer 'init()' with type '()'; do you want to add a stub?}} {{43-43=\n init() {\n <#code#>\n \}\n}}
144-
}
145-
146142
struct Location {
147143
var x : Int
148144
var y : Int
@@ -152,6 +148,9 @@ struct Location {
152148
}
153149
}
154150

151+
protocol DefaultConstructable {
152+
init() // expected-note {{protocol requires initializer 'init()' with type '()'; do you want to add a stub?}} {{+2:43-43=\n init() {\n <#code#>\n \}\n}}
153+
}
155154
extension Location: DefaultConstructable {} // expected-error {{type 'Location' does not conform to protocol 'DefaultConstructable'}}
156155

157156
extension Location: AsyncDefaultConstructable {}

test/Concurrency/require-explicit-sendable.swift

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,41 +2,41 @@
22

33
public protocol P { }
44

5+
// expected-note@+2{{consider making struct 'S1' conform to the 'Sendable' protocol}}{{18-18=: Sendable}}
6+
// expected-note@+1{{make struct 'S1' explicitly non-Sendable to suppress this warning}}{{+2:2-2=\n\n@available(*, unavailable)\nextension S1: Sendable { \}\n}}
57
public struct S1 { // expected-warning{{public struct 'S1' does not specify whether it is 'Sendable' or not}}
6-
// expected-note@-1{{consider making struct 'S1' conform to the 'Sendable' protocol}}{{18-18=: Sendable}}
7-
// expected-note@-2{{make struct 'S1' explicitly non-Sendable to suppress this warning}}{{2-2=\n\n@available(*, unavailable)\nextension S1: Sendable { \}\n}}
88
var str: String
99
}
1010

1111
class C { }
1212

13+
// expected-note@+2{{add '@unchecked Sendable' conformance to struct 'S2' if this type manually implements concurrency safety}}{{18-18=: @unchecked Sendable}}
14+
// expected-note@+1{{make struct 'S2' explicitly non-Sendable to suppress this warning}}{{+2:2-2=\n\n@available(*, unavailable)\nextension S2: Sendable { \}\n}}
1315
public struct S2 { // expected-warning{{public struct 'S2' does not specify whether it is 'Sendable' or not}}
14-
// expected-note@-1{{add '@unchecked Sendable' conformance to struct 'S2' if this type manually implements concurrency safety}}{{18-18=: @unchecked Sendable}}
15-
// expected-note@-2{{make struct 'S2' explicitly non-Sendable to suppress this warning}}{{2-2=\n\n@available(*, unavailable)\nextension S2: Sendable { \}\n}}
1616
var c: C
1717
}
1818

19+
// expected-note@+2{{consider making class 'C1' conform to the 'Sendable' protocol}}{{25-25=, Sendable}}
20+
// expected-note@+1{{make class 'C1' explicitly non-Sendable to suppress this warning}}{{+2:2-2=\n\n@available(*, unavailable)\nextension C1: Sendable { \}\n}}
1921
final public class C1: P { // expected-warning{{public class 'C1' does not specify whether it is 'Sendable' or not}}
20-
// expected-note@-1{{consider making class 'C1' conform to the 'Sendable' protocol}}{{25-25=, Sendable}}
21-
// expected-note@-2{{make class 'C1' explicitly non-Sendable to suppress this warning}}{{2-2=\n\n@available(*, unavailable)\nextension C1: Sendable { \}\n}}
2222
let str: String = ""
2323
}
2424

25+
// expected-note@+2{{add '@unchecked Sendable' conformance to class 'C2' if this type manually implements concurrency safety}}{{17-17=: @unchecked Sendable}}
26+
// expected-note@+1{{make class 'C2' explicitly non-Sendable to suppress this warning}}{{+2:2-2=\n\n@available(*, unavailable)\nextension C2: Sendable { \}\n}}
2527
public class C2 { // expected-warning{{public class 'C2' does not specify whether it is 'Sendable' or not}}
26-
// expected-note@-1{{add '@unchecked Sendable' conformance to class 'C2' if this type manually implements concurrency safety}}{{17-17=: @unchecked Sendable}}
27-
// expected-note@-2{{make class 'C2' explicitly non-Sendable to suppress this warning}}{{2-2=\n\n@available(*, unavailable)\nextension C2: Sendable { \}\n}}
2828
var str: String = ""
2929
}
3030

31+
// expected-note@+2{{consider making generic struct 'S3' conform to the 'Sendable' protocol}}{{+2:2-2=\n\nextension S3: Sendable where T: Sendable { \}\n}}
32+
// expected-note@+1{{make generic struct 'S3' explicitly non-Sendable to suppress this warning}}{{+2:2-2=\n\n@available(*, unavailable)\nextension S3: Sendable { \}\n}}
3133
public struct S3<T> { // expected-warning{{public generic struct 'S3' does not specify whether it is 'Sendable' or not}}
32-
// expected-note@-1{{consider making generic struct 'S3' conform to the 'Sendable' protocol}}{{2-2=\n\nextension S3: Sendable where T: Sendable { \}\n}}
33-
// expected-note@-2{{make generic struct 'S3' explicitly non-Sendable to suppress this warning}}{{2-2=\n\n@available(*, unavailable)\nextension S3: Sendable { \}\n}}
3434
var t: T
3535
}
3636

37+
// expected-note@+2{{add '@unchecked Sendable' conformance to generic struct 'S4' if this type manually implements concurrency safety}}{{+3:2-2=\n\nextension S4: @unchecked Sendable where T: Sendable { \}\n}}
38+
// expected-note@+1{{make generic struct 'S4' explicitly non-Sendable to suppress this warning}}{{+3:2-2=\n\n@available(*, unavailable)\nextension S4: Sendable { \}\n}}
3739
public struct S4<T> { // expected-warning{{public generic struct 'S4' does not specify whether it is 'Sendable' or not}}
38-
// expected-note@-1{{add '@unchecked Sendable' conformance to generic struct 'S4' if this type manually implements concurrency safety}}{{2-2=\n\nextension S4: @unchecked Sendable where T: Sendable { \}\n}}
39-
// expected-note@-2{{make generic struct 'S4' explicitly non-Sendable to suppress this warning}}{{2-2=\n\n@available(*, unavailable)\nextension S4: Sendable { \}\n}}
4040
var t: T
4141
var c: C
4242
}
@@ -71,20 +71,20 @@ func testMe(s5: S5, s7: S7) {
7171
acceptSendable(s7) // expected-warning{{conformance of 'S7' to 'Sendable' is unavailable}}
7272
}
7373

74+
// expected-note@+2{{consider making generic struct 'S8' conform to the 'Sendable' protocol}}{{+2:2-2=\n\nextension S8: Sendable where T: Sendable, U: Sendable, V: Sendable { \}\n}}
75+
// expected-note@+1{{make generic struct 'S8' explicitly non-Sendable to suppress this warning}}
7476
public struct S8<T: Hashable, U, V> { // expected-warning{{public generic struct 'S8' does not specify whether it is 'Sendable' or not}}
75-
// expected-note@-1{{consider making generic struct 'S8' conform to the 'Sendable' protocol}}{{2-2=\n\nextension S8: Sendable where T: Sendable, U: Sendable, V: Sendable { \}\n}}
76-
// expected-note@-2{{make generic struct 'S8' explicitly non-Sendable to suppress this warning}}
7777
var member: [T: (U, V?)]
7878
}
7979

8080
public protocol P2 {
8181
associatedtype A
8282
}
8383

84+
// expected-warning@+3{{public generic struct 'S9' does not specify whether it is 'Sendable' or not}}
85+
// expected-note@+2{{consider making generic struct 'S9' conform to the 'Sendable' protocol}}{{+2:2-2=\n\nextension S9: Sendable where T: Sendable, T.A: Sendable { \}\n}}
86+
// expected-note@+1{{make generic struct 'S9' explicitly non-Sendable to suppress this warning}}
8487
public struct S9<T: P2 & Hashable> {
85-
// expected-warning@-1{{public generic struct 'S9' does not specify whether it is 'Sendable' or not}}
86-
// expected-note@-2{{consider making generic struct 'S9' conform to the 'Sendable' protocol}}{{2-2=\n\nextension S9: Sendable where T: Sendable, T.A: Sendable { \}\n}}
87-
// expected-note@-3{{make generic struct 'S9' explicitly non-Sendable to suppress this warning}}
8888
var dict: [T : T.A] = [:]
8989
}
9090

test/Constraints/diagnostics.swift

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1217,74 +1217,74 @@ takesTuple(true) // expected-error {{cannot convert value of type 'Bool' to expe
12171217
func voidFunc() {
12181218
return 1
12191219
// expected-error@-1 {{unexpected non-void return value in void function}}
1220-
// expected-note@-2 {{did you mean to add a return type?}}{{16-16= -> <#Return Type#>}}
1220+
// expected-note@-2 {{did you mean to add a return type?}}{{-1:16-16= -> <#Return Type#>}}
12211221
}
12221222

12231223
func voidFuncWithArgs(arg1: Int) {
12241224
return 1
12251225
// expected-error@-1 {{unexpected non-void return value in void function}}
1226-
// expected-note@-2 {{did you mean to add a return type?}}{{33-33= -> <#Return Type#>}}
1226+
// expected-note@-2 {{did you mean to add a return type?}}{{-1:33-33= -> <#Return Type#>}}
12271227
}
12281228

12291229
func voidFuncWithCondFlow() {
12301230
if Bool.random() {
12311231
return 1
12321232
// expected-error@-1 {{unexpected non-void return value in void function}}
1233-
// expected-note@-2 {{did you mean to add a return type?}}{{28-28= -> <#Return Type#>}}
1233+
// expected-note@-2 {{did you mean to add a return type?}}{{-2:28-28= -> <#Return Type#>}}
12341234
} else {
12351235
return 2
12361236
// expected-error@-1 {{unexpected non-void return value in void function}}
1237-
// expected-note@-2 {{did you mean to add a return type?}}{{28-28= -> <#Return Type#>}}
1237+
// expected-note@-2 {{did you mean to add a return type?}}{{-6:28-28= -> <#Return Type#>}}
12381238
}
12391239
}
12401240

12411241
func voidFuncWithNestedVoidFunc() {
12421242
func nestedVoidFunc() {
12431243
return 1
12441244
// expected-error@-1 {{unexpected non-void return value in void function}}
1245-
// expected-note@-2 {{did you mean to add a return type?}}{{24-24= -> <#Return Type#>}}
1245+
// expected-note@-2 {{did you mean to add a return type?}}{{-1:24-24= -> <#Return Type#>}}
12461246
}
12471247
}
12481248

12491249
func voidFuncWithEffects1() throws {
12501250
return 1
12511251
// expected-error@-1 {{unexpected non-void return value in void function}}
1252-
// expected-note@-2 {{did you mean to add a return type?}}{{35-35= -> <#Return Type#>}}
1252+
// expected-note@-2 {{did you mean to add a return type?}}{{-1:35-35= -> <#Return Type#>}}
12531253
}
12541254

12551255
@available(SwiftStdlib 5.5, *)
12561256
func voidFuncWithEffects2() async throws {
12571257
return 1
12581258
// expected-error@-1 {{unexpected non-void return value in void function}}
1259-
// expected-note@-2 {{did you mean to add a return type?}}{{41-41= -> <#Return Type#>}}
1259+
// expected-note@-2 {{did you mean to add a return type?}}{{-1:41-41= -> <#Return Type#>}}
12601260
}
12611261

12621262
@available(SwiftStdlib 5.5, *)
12631263
// expected-error@+1 {{'async' must precede 'throws'}}
12641264
func voidFuncWithEffects3() throws async {
12651265
return 1
12661266
// expected-error@-1 {{unexpected non-void return value in void function}}
1267-
// expected-note@-2 {{did you mean to add a return type?}}{{41-41= -> <#Return Type#>}}
1267+
// expected-note@-2 {{did you mean to add a return type?}}{{-1:41-41= -> <#Return Type#>}}
12681268
}
12691269

12701270
@available(SwiftStdlib 5.5, *)
12711271
func voidFuncWithEffects4() async {
12721272
return 1
12731273
// expected-error@-1 {{unexpected non-void return value in void function}}
1274-
// expected-note@-2 {{did you mean to add a return type?}}{{34-34= -> <#Return Type#>}}
1274+
// expected-note@-2 {{did you mean to add a return type?}}{{-1:34-34= -> <#Return Type#>}}
12751275
}
12761276

12771277
func voidFuncWithEffects5(_ closure: () throws -> Void) rethrows {
12781278
return 1
12791279
// expected-error@-1 {{unexpected non-void return value in void function}}
1280-
// expected-note@-2 {{did you mean to add a return type?}}{{65-65= -> <#Return Type#>}}
1280+
// expected-note@-2 {{did you mean to add a return type?}}{{-1:65-65= -> <#Return Type#>}}
12811281
}
12821282

12831283
@available(SwiftStdlib 5.5, *)
12841284
func voidGenericFuncWithEffects<T>(arg: T) async where T: CustomStringConvertible {
12851285
return 1
12861286
// expected-error@-1 {{unexpected non-void return value in void function}}
1287-
// expected-note@-2 {{did you mean to add a return type?}}{{49-49= -> <#Return Type#>}}
1287+
// expected-note@-2 {{did you mean to add a return type?}}{{-1:49-49= -> <#Return Type#>}}
12881288
}
12891289

12901290
// Special cases: These should not offer a note + fix-it

test/Constraints/result_builder_diags.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,8 @@ struct MyTuplifiedStruct {
299299

300300
@TupleBuilder var computed: some Any { // expected-note{{remove the attribute to explicitly disable the result builder}}{{3-17=}}
301301
if condition {
302+
// expected-note@+1 {{remove 'return' statements to apply the result builder}}{{7-14=}}{{+2:12-19=}}
302303
return 17 // expected-warning{{application of result builder 'TupleBuilder' disabled by explicit 'return' statement}}
303-
// expected-note@-1{{remove 'return' statements to apply the result builder}}{{7-14=}}{{12-19=}}
304304
} else {
305305
return 42
306306
}

test/Constraints/result_builder_infer.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,11 +152,11 @@ struct AmbigTupleMe: Tupled, OtherTupled {
152152
var condition: Bool
153153

154154
// Ambiguous
155+
// expected-note@+4{{add an explicit 'return' statement to not use a result builder}}{{+3:3-3=return <#expr#>\n}}
156+
// expected-note@+3{{apply result builder 'TupleBuilder' (inferred from protocol 'Tupled')}}{{-1:3-3=@TupleBuilder }}
157+
// expected-note@+2{{apply result builder 'OtherTupleBuilder' (inferred from protocol 'OtherTupled')}}{{-1:3-3=@OtherTupleBuilder }}
155158
internal
156159
var tuple: Void { // expected-error{{ambiguous result builder inferred for 'tuple': 'TupleBuilder' or 'OtherTupleBuilder'}}
157-
// expected-note@-1{{add an explicit 'return' statement to not use a result builder}}{{3-3=return <#expr#>\n}}
158-
// expected-note@-2{{apply result builder 'TupleBuilder' (inferred from protocol 'Tupled')}}{{3-3=@TupleBuilder }}
159-
// expected-note@-3{{apply result builder 'OtherTupleBuilder' (inferred from protocol 'OtherTupled')}}{{3-3=@OtherTupleBuilder }}
160160
"hello" // expected-warning{{string literal is unused}}
161161
"world" // expected-warning{{string literal is unused}}
162162
}

test/Constraints/tuple_arguments.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1500,9 +1500,9 @@ let r31892961_1 = [1: 1, 2: 2]
15001500
r31892961_1.forEach { (k, v) in print(k + v) }
15011501

15021502
let r31892961_2 = [1, 2, 3]
1503+
// expected-error@+2 {{closure tuple parameter does not support destructuring}} {{48-60=arg0}} {{+1:3-3=\n let (index, val) = arg0\n }}
1504+
// expected-warning@+1 {{unnamed parameters must be written with the empty name '_'}} {{48-48=_: }}
15031505
let _: [Int] = r31892961_2.enumerated().map { ((index, val)) in
1504-
// expected-error@-1 {{closure tuple parameter does not support destructuring}} {{48-60=arg0}} {{3-3=\n let (index, val) = arg0\n }}
1505-
// expected-warning@-2 {{unnamed parameters must be written with the empty name '_'}} {{48-48=_: }}
15061506
val + 1
15071507
// expected-error@-1 {{cannot find 'val' in scope}}
15081508
}

test/Distributed/distributed_protocol_isolation.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ typealias DefaultDistributedActorSystem = FakeActorSystem
1414
// MARK: Distributed actor protocols
1515

1616
protocol WrongDistFuncs {
17-
distributed func notDistActor() // expected-error{{'distributed' method can only be declared within 'distributed actor'}}{{5-17=}} {{25-25=: DistributedActor}}
17+
distributed func notDistActor() // expected-error{{'distributed' method can only be declared within 'distributed actor'}}{{5-17=}} {{-1:25-25=: DistributedActor}}
1818
}
1919

2020
protocol DistProtocol: DistributedActor {

0 commit comments

Comments
 (0)