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
pull/16/head
韩天峰 2 months ago
parent 2bad099e09
commit d251331ae4
  1. 5
      src/Translator.php

@ -4070,7 +4070,8 @@ CODE;
} }
$argv = implode(', ', $argList); $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) { if ($this->class) {
$code .= self::TYPE_OBJECT . ' &this_'; $code .= self::TYPE_OBJECT . ' &this_';
if ($methodDef->functionDef->params) { if ($methodDef->functionDef->params) {
@ -4084,7 +4085,7 @@ CODE;
$code .= '{' . PHP_EOL; $code .= '{' . PHP_EOL;
$this->indentLevel++; $this->indentLevel++;
$methodCall = self::PREFIX . $traitMethodNativeName . '(' . $argv . ')'; $methodCall = self::PREFIX . $traitMethodNativeName . '(' . $argv . ')';
if ($methodDef->getReturnType() !== self::TYPE_VOID) { if ($cppReturnType !== self::TYPE_VOID) {
$methodCall = 'return ' . $methodCall; $methodCall = 'return ' . $methodCall;
} }
$code .= $this->getIndent() . $methodCall . ';' . PHP_EOL; $code .= $this->getIndent() . $methodCall . ';' . PHP_EOL;

Loading…
Cancel
Save