Skip to content

Commit 6d71c3b

Browse files
authored
fix(query): iterate over multiple predicates properly (#69)
1 parent d0bb551 commit 6d71c3b

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

  • ktreesitter/src
    • commonTest/kotlin/io/github/treesitter/ktreesitter
    • nativeMain/kotlin/io/github/treesitter/ktreesitter

ktreesitter/src/commonTest/kotlin/io/github/treesitter/ktreesitter/QueryTest.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,4 +164,17 @@ class QueryTest :
164164
query.isPatternGuaranteedAtStep(99U)
165165
}
166166
}
167+
168+
test("multiple predicates on same pattern") {
169+
shouldNotThrowAny {
170+
Query(
171+
language,
172+
"""
173+
((identifier) @x
174+
(#eq? @x "foo")
175+
(#eq? @x "bar"))
176+
""".trimIndent()
177+
)
178+
}
179+
}
167180
})

ktreesitter/src/nativeMain/kotlin/io/github/treesitter/ktreesitter/Query.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,9 @@ actual class Query @Throws(QueryError::class) actual constructor(
279279
}
280280

281281
j += nargs.toUInt() + 1U
282-
tokens = interpretCPointer(tokens.rawValue + nargs)!!
282+
tokens = interpretCPointer(
283+
tokens.rawValue + (nargs + 1L) * sizeOf<TSQueryPredicateStep>()
284+
)!!
283285
}
284286
}
285287
}

0 commit comments

Comments
 (0)