Skip to content

Language: scalar union types — compile abort Unknown Op\Type\Union_ (regression vs #6850/#6833) #7327

Description

@PurHur

Category

language · php-src-strict · regression

Problem

Scalar union types (int|string, ?float, DNF arms containing unions) abort compile with:

Unknown Op\Type provided: PHPCfg\Op\Type\Union_

Closed #6850 / #6833 tracked this gap; Docker repro (Jun 2026) shows all union sites fail again — function parameters, return types, promoted properties, and declared instance properties. Intersection types (A&B) still compile.

Self-host and modern PHP sources using unions cannot compile on VM/JIT/AOT.

php-src reference

Repro (failure today)

Parameter union:

<?php
function f(int|string $x): void {
    echo $x;
}
f(1);

Declared property union:

<?php
class C {
    public int|string $p;
}
$c = new C();
try {
    var_dump($c->p);
} catch (Error $e) {
    echo $e->getMessage(), "\n";
}
./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && ./script/apply-patches.sh
php bin/vm.php test/repro/maintainer_union_uninit.php 2>&1 | head -3
php bin/vm.php /tmp/param_union.php 2>&1 | head -3   # write repro files as above
'
Site Zend VM today
function f(int|string $x) compiles Unknown Op\Type\Union_ ❌
public int|string $p compiles Unknown Op\Type\Union_ ❌
function f(A&B $x) compiles compiles ✅

Scope (this repo)

Layer Path
Compiler lib/Compiler.php — compileTypeConstrainedVariable, TYPE_DECLARE_PROPERTY, param/return type lowering for Union_
VM lib/VM/TypeCheck.php — per-arm verify on read/write
JIT/AOT phase 2 after VM green (lib/JIT/TypeCheck.php, DNF helpers)
Tests test/compliance/cases/types/scalar_union_param.phpt, scalar_union_property.phpt

PHP-in-PHP: union lowering in lib/; no new runtime/*.c.

Done when

  • Parameter and property union repros compile on VM
  • Uninitialized union property read throws catchable Error like Zend (not Union_ abort)
  • Intersection-only types remain green (no regression)
  • ./script/ci-fast.sh --filter scalar_union green

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh && vendor/bin/phpunit --filter scalar_union'

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