Skip to content

Commit 12f4ccc

Browse files
authored
Resolve various warnings that were recently introduced (#1744)
1 parent c3226e6 commit 12f4ccc

File tree

7 files changed

+23
-22
lines changed

7 files changed

+23
-22
lines changed

Sources/FoundationEssentials/Data/DataProtocol.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ extension Data : MutableDataProtocol {
241241
}
242242
}
243243

244+
@available(macOS 10.10, iOS 8.0, watchOS 2.0, tvOS 9.0, *)
244245
extension Data {
245246
/// Copy the contents of the data to a pointer.
246247
///

Sources/FoundationEssentials/Platform.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,9 @@ extension Platform {
368368
if let processPath = CommandLine.arguments.first {
369369
return processPath
370370
}
371+
return nil
372+
#else
373+
return nil
371374
#endif
372-
return nil
373375
}
374376
}

Sources/FoundationEssentials/Predicate/Archiving/EncodingContainers+PredicateExpression.swift

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,7 @@ extension UnkeyedDecodingContainer {
7070
public mutating func decodePredicateExpression<each Input>(input: repeat (each Input).Type, predicateConfiguration: PredicateCodableConfiguration) throws -> (expression: any PredicateExpression<Bool>, variable: (repeat PredicateExpressions.Variable<each Input>)) {
7171
var container = try self.nestedContainer(keyedBy: PredicateExpressionCodingKeys.self)
7272
let (expr, variable) = try container._decode(input: repeat each input, output: Bool.self, predicateConfiguration: predicateConfiguration)
73-
guard let casted = expr as? any PredicateExpression<Bool> else {
74-
throw DecodingError.dataCorruptedError(in: self, debugDescription: "This expression has an unsupported output type of \(_typeName(type(of: expr).outputType)) (expected Bool)")
75-
}
76-
return (casted, variable)
73+
return (expr as any PredicateExpression<Bool>, variable)
7774
}
7875

7976
public mutating func decodePredicateExpressionIfPresent<each Input>(input: repeat (each Input).Type, predicateConfiguration: PredicateCodableConfiguration) throws -> (expression: any PredicateExpression<Bool>, variable: (repeat PredicateExpressions.Variable<each Input>))? {

Sources/FoundationEssentials/ProgressManager/ProgressFraction.swift

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -297,20 +297,21 @@ internal struct ProgressFraction : Sendable, Equatable, CustomDebugStringConvert
297297
}
298298

299299
internal var debugDescription : String {
300-
return "\(completed) / \(total) (\(fractionCompleted)), overflowed: \(overflowed)"
300+
return "\(completed) / \(total, default: "unknown") (\(fractionCompleted)), overflowed: \(overflowed)"
301301
}
302302

303303
// ----
304304

305305
private static func _fromDouble(_ d : Double) -> (Int, Int) {
306306
// This simplistic algorithm could someday be replaced with something better.
307307
// Basically - how many 1/Nths is this double?
308-
var denominator: Int
309-
switch Int.bitWidth {
310-
case 32: denominator = 1048576 // 2^20 - safe for 32-bit
311-
case 64: denominator = 1073741824 // 2^30 - high precision for 64-bit
312-
default: denominator = 131072 // 2^17 - ultra-safe fallback
313-
}
308+
#if _pointerBitWidth(_32)
309+
let denominator = 1048576 // 2^20 - safe for 32-bit
310+
#elseif _pointerBitWidth(_64)
311+
let denominator = 1073741824 // 2^30 - high precision for 64-bit
312+
#else
313+
let denominator = 131072 // 2^17 - ultra-safe fallback
314+
#endif
314315
let numerator = Int(d / (1.0 / Double(denominator)))
315316
return (numerator, denominator)
316317
}

Tests/FoundationEssentialsTests/DataTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1737,7 +1737,7 @@ private final class DataTests {
17371737
#expect(span.count == count)
17381738
let v = UInt8.random(in: 10..<100)
17391739
span[i] = v
1740-
var sub = span.extracting(i ..< i+1)
1740+
var sub = span._mutatingExtracting(i ..< i+1)
17411741
sub.update(repeating: v)
17421742
#expect(source[i] == v)
17431743
#endif
@@ -1751,7 +1751,7 @@ private final class DataTests {
17511751
var span = source.mutableSpan
17521752
#expect(span.count == count)
17531753
let i = try #require(span.indices.randomElement())
1754-
var sub = span.extracting(i..<i+1)
1754+
var sub = span._mutatingExtracting(i..<i+1)
17551755
sub.update(repeating: .max)
17561756
#expect(source[i] == .max)
17571757
#endif
@@ -1773,7 +1773,7 @@ private final class DataTests {
17731773
let byteCount = span.byteCount
17741774
#expect(byteCount == count)
17751775
let v = UInt8.random(in: 10..<100)
1776-
var sub = span.extracting(i..<i+1)
1776+
var sub = span._mutatingExtracting(i..<i+1)
17771777
sub.storeBytes(of: v, as: UInt8.self)
17781778
#expect(source[i] == v)
17791779
}

Tests/FoundationEssentialsTests/ProgressManager/ProgressManagerTests.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -399,10 +399,10 @@ extension Tag {
399399

400400
manager.complete(count: 1)
401401

402-
var subprogress: Subprogress? = manager.subprogress(assigningCount: 1)
403-
#expect(manager.fractionCompleted == 0.5)
404-
405-
subprogress = nil
402+
withExtendedLifetime(manager.subprogress(assigningCount: 1)) {
403+
#expect(manager.fractionCompleted == 0.5)
404+
}
405+
406406
#expect(manager.fractionCompleted == 1.0)
407407
}
408408

Tests/FoundationInternationalizationTests/Formatting/DateRelativeFormatStyleTests.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ private struct TestDateAnchoredRelativeDiscreteConformance {
485485
sourceLocation: sourceLocation)
486486
}
487487

488-
var now = try date("2021-06-10 12:00:00Z")
488+
var now = date("2021-06-10 12:00:00Z")
489489

490490
assertEvaluation(
491491
of: .init(anchor: now, presentation: .numeric, unitsStyle: .abbreviated),
@@ -565,7 +565,7 @@ private struct TestDateAnchoredRelativeDiscreteConformance {
565565
"8 mo. ago",
566566
])
567567

568-
now = try date("2023-05-15 08:47:20Z")
568+
now = date("2023-05-15 08:47:20Z")
569569

570570
assertEvaluation(
571571
of: .init(anchor: now, allowedFields: [.month, .week], presentation: .numeric, unitsStyle: .abbreviated),
@@ -685,7 +685,7 @@ private struct TestDateAnchoredRelativeDiscreteConformance {
685685
"8 mo. ago",
686686
])
687687

688-
now = try date("2019-06-03 09:41:00Z")
688+
now = date("2019-06-03 09:41:00Z")
689689

690690
assertEvaluation(
691691
of: .init(anchor: now, allowedFields: [.year, .month, .day, .hour, .minute], presentation: .named, unitsStyle: .wide),

0 commit comments

Comments
 (0)