Skip to content

Language: never in union types — Unknown Op\Type\Union_ instead of Zend compile fatal (pairs #6967) #7329

Description

@PurHur

Category

language · php-src-strict

Problem

Using never inside a union type (int|never, function f(int|never $x)) must be rejected at compile time with Zend's message:

never can only be used as a standalone type

This compiler dies earlier with Unknown Op\Type provided: PHPCfg\Op\Type\Union_ — same abort as general union regression (#7327), but never-in-union needs an explicit guard so workers do not confuse it with scalar union lowering.

Standalone never (function f(): never, never $p) must keep compiling.

php-src reference

Repro

test/repro/never_union_property.php:

<?php
class C {
    public int|never $x;
}
echo "ok\n";
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/repro/never_union_property.php 2>&1 | head -1
php -r "class C { public int|never \$x; }" 2>&1 | head -1   # PHP 8.x reference when available
'
Engine Message
Zend never can only be used as a standalone type
VM Unknown Op\Type\Union_

Also verify parameter declarations: function f(int|never $x).

Scope (this repo)

Path Work
lib/Compiler.php Before union CFG lowering: scan type arms for Never_; throwCompileError('never can only be used as a standalone type')
Tests test/compliance/cases/language/never_union_type.phpt (property + parameter)

Coordinate with #7327 scalar union lowering — this issue is the never-specific guard + message even if union compile is fixed separately.

Done when

  • Repro exits 255 with exact Zend message (not Unknown Op\Type\Union_)
  • Standalone never types still compile
  • ./script/ci-fast.sh --filter never_union_type green

Related

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:compilerCompiler / CFG / JITarea:vmVirtual machineenhancementNew feature or requestimplementation-readySpec complete: repro, php-src ref, done-when — safe for workers to claimphase-2:languagePhase 2 – language features

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions