|
12 | 12 | public struct SourceLocation: Sendable { |
13 | 13 | /// The file ID of the source file. |
14 | 14 | /// |
| 15 | + /// - Precondition: The value of this property must not be empty and must be |
| 16 | + /// formatted as described in the documentation for the |
| 17 | + /// [`#fileID`](https://developer.apple.com/documentation/swift/fileID()). |
| 18 | + /// macro in the Swift standard library. |
| 19 | + /// |
15 | 20 | /// ## See Also |
16 | 21 | /// |
17 | 22 | /// - ``moduleName`` |
18 | 23 | /// - ``fileName`` |
19 | 24 | public var fileID: String { |
20 | | - didSet { |
21 | | - precondition(!fileID.isEmpty) |
22 | | - precondition(fileID.contains("/")) |
| 25 | + willSet { |
| 26 | + precondition(!newValue.isEmpty, "SourceLocation.fileID must not be empty (was \(newValue))") |
| 27 | + precondition(newValue.contains("/"), "SourceLocation.fileID must be a well-formed file ID (was \(newValue))") |
23 | 28 | } |
24 | 29 | } |
25 | 30 |
|
@@ -74,20 +79,45 @@ public struct SourceLocation: Sendable { |
74 | 79 | public var _filePath: String |
75 | 80 |
|
76 | 81 | /// The line in the source file. |
| 82 | + /// |
| 83 | + /// - Precondition: The value of this property must be greater than `0`. |
77 | 84 | public var line: Int { |
78 | | - didSet { |
79 | | - precondition(line > 0) |
| 85 | + willSet { |
| 86 | + precondition(newValue > 0, "SourceLocation.line must be greater than 0 (was \(newValue))") |
80 | 87 | } |
81 | 88 | } |
82 | 89 |
|
83 | 90 | /// The column in the source file. |
| 91 | + /// |
| 92 | + /// - Precondition: The value of this property must be greater than `0`. |
84 | 93 | public var column: Int { |
85 | | - didSet { |
86 | | - precondition(column > 0) |
| 94 | + willSet { |
| 95 | + precondition(newValue > 0, "SourceLocation.column must be greater than 0 (was \(newValue))") |
87 | 96 | } |
88 | 97 | } |
89 | 98 |
|
| 99 | + /// Initialize an instance of this type with the specified location details. |
| 100 | + /// |
| 101 | + /// - Parameters: |
| 102 | + /// - fileID: The file ID of the source file, using the format described in |
| 103 | + /// the documentation for the |
| 104 | + /// [`#fileID`](https://developer.apple.com/documentation/swift/fileID()) |
| 105 | + /// macro in the Swift standard library. |
| 106 | + /// - filePath: The path to the source file. |
| 107 | + /// - line: The line in the source file. Must be greater than `0`. |
| 108 | + /// - column: The column in the source file. Must be greater than `0`. |
| 109 | + /// |
| 110 | + /// - Precondition: `fileID` must not be empty and must be formatted as |
| 111 | + /// described in the documentation for |
| 112 | + /// [`#fileID`](https://developer.apple.com/documentation/swift/fileID()). |
| 113 | + /// - Precondition: `line` must be greater than `0`. |
| 114 | + /// - Precondition: `column` must be greater than `0`. |
90 | 115 | public init(fileID: String, filePath: String, line: Int, column: Int) { |
| 116 | + precondition(!fileID.isEmpty, "SourceLocation.fileID must not be empty (was \(fileID))") |
| 117 | + precondition(fileID.contains("/"), "SourceLocation.fileID must be a well-formed file ID (was \(fileID))") |
| 118 | + precondition(line > 0, "SourceLocation.line must be greater than 0 (was \(line))") |
| 119 | + precondition(column > 0, "SourceLocation.column must be greater than 0 (was \(column))") |
| 120 | + |
91 | 121 | self.fileID = fileID |
92 | 122 | self._filePath = filePath |
93 | 123 | self.line = line |
|
0 commit comments