Skip to content

Commit 4b0a98a

Browse files
committed
Allow native token stream in trait constructor
The SQLite driver passes a WP_MySQL_Native_Token_Stream object as the $tokens argument when the extension is loaded; pre-PR this worked because the parent class was the Rust WP_MySQL_Native_Parser, which accepts either an array or the stream object. The trait's constructor needs the same flexibility — drop the array typehint and pass an empty array to WP_Parser::__construct, whose tokens/position state is inert in native mode.
1 parent 26638ce commit 4b0a98a

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

packages/mysql-on-sqlite/src/mysql/native/trait-wp-mysql-native-parser-impl.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,24 @@ trait WP_MySQL_Native_Parser_Impl {
2020
*/
2121
private $native;
2222

23-
public function __construct( WP_Parser_Grammar $grammar, array $tokens ) {
24-
parent::__construct( $grammar, $tokens );
23+
/**
24+
* @param WP_Parser_Grammar $grammar
25+
* @param array<WP_Parser_Token>|WP_MySQL_Native_Token_Stream $tokens
26+
*/
27+
public function __construct( WP_Parser_Grammar $grammar, $tokens ) {
28+
// WP_Parser's `array $tokens` constructor signature can't accept
29+
// the native token stream object; its `$this->tokens` /
30+
// `$this->position` state is inert in native mode anyway, so we
31+
// pass an empty array to satisfy the parent contract and keep
32+
// the actual tokens on the native parser.
33+
parent::__construct( $grammar, array() );
2534
$this->native = new WP_MySQL_Native_Parser( $grammar, $tokens );
2635
}
2736

28-
public function reset_tokens( array $tokens ): void {
37+
/**
38+
* @param array<WP_Parser_Token>|WP_MySQL_Native_Token_Stream $tokens
39+
*/
40+
public function reset_tokens( $tokens ): void {
2941
$this->native->reset_tokens( $tokens );
3042
}
3143

0 commit comments

Comments
 (0)