Skip to content

Fatal error when transforming function with never return type #514

@JJCLane

Description

@JJCLane

Given a function that declares a never return type.

final public function unwrap(): never
{
    if ($this->value instanceof \Throwable) {
        throw $this->value;
    }

    throw new \RuntimeException(\sprintf("Unwrapping `Err`: %s", \serialize($this->value)));
}

It gets transformed into the following code with an added statement return $__am_res; and causes PHP to throw a fatal exception:
Fatal error: A never-returning function must not return in Err.php on line 55

final public function unwrap(): never
{ if (($__am_res = __amock_before($this, __CLASS__, __FUNCTION__, array(), false)) !== __AM_CONTINUE__) return $__am_res;
    if ($this->value instanceof \Throwable) {
        throw $this->value;
    }

    throw new \RuntimeException(\sprintf("Unwrapping `Err`: %s", \serialize($this->value)));
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions