Skip to content

Commit 32ecb28

Browse files
committed
[ASTGen] Remove usage of methods that shouldn’t be part of SwiftSynax’s public API
1 parent ce44301 commit 32ecb28

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/ASTGen/Sources/ASTGen/Generics.swift

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,20 @@ extension ASTGenVisitor {
2323
let nameLoc = self.base.advanced(by: node.name.position.utf8Offset).raw
2424
let eachLoc = node.each.map { self.base.advanced(by: $0.position.utf8Offset).raw }
2525

26+
var genericParameterIndex: Int?
27+
for (index, sibling) in (node.parent?.as(GenericParameterListSyntax.self) ?? []).enumerated() {
28+
if sibling == node {
29+
genericParameterIndex = index
30+
break
31+
}
32+
}
33+
guard let genericParameterIndex = genericParameterIndex else {
34+
preconditionFailure("Node not part of the parent?")
35+
}
36+
2637
return .decl(
2738
GenericTypeParamDecl_create(
28-
self.ctx, self.declContext, name, nameLoc, eachLoc, node.indexInParent / 2,
39+
self.ctx, self.declContext, name, nameLoc, eachLoc, genericParameterIndex,
2940
eachLoc != nil))
3041
}
3142
}

test/Macros/Inputs/syntax_macro_definitions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public enum AddBlocker: ExpressionMacro {
136136
ExprSyntax(
137137
binOp.with(
138138
\.operatorToken,
139-
binOp.operatorToken.withKind(.binaryOperator("-"))
139+
binOp.operatorToken.with(\.tokenKind, .binaryOperator("-"))
140140
)
141141
)
142142
)

0 commit comments

Comments
 (0)