Skip to content

Commit 7932c90

Browse files
committed
address build failures
1 parent e06c1d6 commit 7932c90

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

lib/Macros/Sources/SwiftMacros/PointerBoundsMacro.swift

+17-18
Original file line numberDiff line numberDiff line change
@@ -125,16 +125,14 @@ func replaceTypeName(_ type: TypeSyntax, _ name: TokenSyntax) -> TypeSyntax {
125125
return TypeSyntax(idType.with(\.name, name))
126126
}
127127

128-
func getPointerMutability(text: String) -> Mutability {
128+
func getPointerMutability(text: String) -> Mutability? {
129129
switch text {
130130
case "UnsafePointer": return .Immutable
131131
case "UnsafeMutablePointer": return .Mutable
132132
case "UnsafeRawPointer": return .Immutable
133133
case "UnsafeMutableRawPointer": return .Mutable
134134
default:
135-
throw DiagnosticError(
136-
"expected Unsafe[Mutable][Raw]Pointer type for type \(prev)"
137-
+ " - first type token is '\(text)'", node: name)
135+
return nil
138136
}
139137
}
140138

@@ -166,8 +164,11 @@ func transformType(_ prev: TypeSyntax, _ variant: Variant, _ isSizedBy: Bool) th
166164
throw DiagnosticError("raw pointers only supported for SizedBy", node: name)
167165
}
168166

169-
let kind: Mutability =
170-
getPointerMutability(text: text)
167+
guard let kind: Mutability = getPointerMutability(text: text) else {
168+
throw DiagnosticError(
169+
"expected Unsafe[Mutable][Raw]Pointer type for type \(prev)"
170+
+ " - first type token is '\(text)'", node: name)
171+
}
171172
let token = getSafePointerName(mut: kind, generateSpan: variant.generateSpan, isRaw: isSizedBy)
172173
if isSizedBy {
173174
return TypeSyntax(IdentifierTypeSyntax(name: token))
@@ -543,7 +544,7 @@ public struct PointerBoundsMacro: PeerMacro {
543544
let endParamIndexArg = try getArgumentByName(argumentList, "end")
544545
let endParamIndex: Int = try getIntLiteralValue(endParamIndexArg)
545546
let nonescapingExprArg = getOptionalArgumentByName(argumentList, "nonescaping")
546-
let nonescaping = nonescapingExprArg != nil && try getBoolLiteralValue(nonescapingExprArg!)
547+
let nonescaping = try nonescapingExprArg != nil && getBoolLiteralValue(nonescapingExprArg!)
547548
return EndedBy(
548549
pointerIndex: startParamIndex, endIndex: endParamIndex, nonescaping: nonescaping,
549550
original: ExprSyntax(enumConstructorExpr))
@@ -615,10 +616,9 @@ public struct PointerBoundsMacro: PeerMacro {
615616
let i = pointerArg.pointerIndex
616617
if i < 1 || i > paramCount {
617618
let noteMessage =
618-
paramCount > 0 ?
619-
"function \(funcDecl.name) has parameter indices 1..\(paramCount)"
620-
:
621-
"function \(funcDecl.name) has no parameters"
619+
paramCount > 0
620+
? "function \(funcDecl.name) has parameter indices 1..\(paramCount)"
621+
: "function \(funcDecl.name) has no parameters"
622622
throw DiagnosticError(
623623
"pointer index out of bounds", node: pointerArg.original,
624624
notes: [
@@ -670,12 +670,11 @@ public struct PointerBoundsMacro: PeerMacro {
670670
})
671671
let newSignature = try builder.buildFunctionSignature([:], variant)
672672
let checks =
673-
variant.skipTrivialCount ?
674-
[] as [CodeBlockItemSyntax]
675-
:
676-
try builder.buildBoundsChecks(variant).map { e in
677-
CodeBlockItemSyntax(leadingTrivia: "\n", item: e)
678-
}
673+
variant.skipTrivialCount
674+
? [] as [CodeBlockItemSyntax]
675+
: try builder.buildBoundsChecks(variant).map { e in
676+
CodeBlockItemSyntax(leadingTrivia: "\n", item: e)
677+
}
679678
let call = CodeBlockItemSyntax(
680679
item: CodeBlockItemSyntax.Item(
681680
ReturnStmtSyntax(
@@ -757,4 +756,4 @@ extension TypeSyntaxProtocol {
757756

758757
return false
759758
}
760-
}
759+
}

0 commit comments

Comments
 (0)