From d251331ae47de00192ecbd99195834d1e1220d46 Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 10 Jul 2026 16:39:51 +0800 Subject: [PATCH] fix(translator): handle reference return types in method generation - Added logic to detect and properly handle reference return types using returnsByRef property - Updated return type determination to include both regular and reference types - Modified condition check to use new cppReturnType variable instead of getReturnType() - Ensured proper return statement generation for reference type methods --- src/Translator.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Translator.php b/src/Translator.php index 60da2d78..aa21c21c 100644 --- a/src/Translator.php +++ b/src/Translator.php @@ -4070,7 +4070,8 @@ CODE; } $argv = implode(', ', $argList); - $code = $methodDef->getReturnType() . ' ' . self::PREFIX . $classMethodNativeName . '('; + $cppReturnType = $methodDef->functionDef->returnsByRef ? self::TYPE_REF : $methodDef->getReturnType(); + $code = $cppReturnType . ' ' . self::PREFIX . $classMethodNativeName . '('; if ($this->class) { $code .= self::TYPE_OBJECT . ' &this_'; if ($methodDef->functionDef->params) { @@ -4084,7 +4085,7 @@ CODE; $code .= '{' . PHP_EOL; $this->indentLevel++; $methodCall = self::PREFIX . $traitMethodNativeName . '(' . $argv . ')'; - if ($methodDef->getReturnType() !== self::TYPE_VOID) { + if ($cppReturnType !== self::TYPE_VOID) { $methodCall = 'return ' . $methodCall; } $code .= $this->getIndent() . $methodCall . ';' . PHP_EOL;