Repository navigation
feat(args): declare untyped and union parameter and return types - #857
Merged
Merged
Conversation
Coverage Report for CI Build 45176341594Coverage increased (+0.3%) to 77.102%Details
Uncovered Changes
Coverage RegressionsNo coverage regressions found. Coverage Stats
💛 - Coveralls |
Merging this PR will not alter performance1 warning
Comparing |
ChiragAgg5k
force-pushed
the
feat/union-untyped-args
branch
from
November 18, 2026 14:22
ddbaee7 to
e005b25
Compare
An internal function's parameter always got a type: `Arg::new` takes a
single `DataType`, and the closest to an untyped `function f($value)` was
`mixed`. Reflection and PHP's inheritance checks see the difference: a PHP
class whose method had an untyped parameter, or an `int|float` one, could
not be reproduced, and code that relied on it had to patch the engine's
copy of the argument info after registration.
- `Arg::untyped(name)` declares a parameter without a type.
- `Arg::or(DataType)` adds a member to a union of scalar types (and `null`):
`Arg::new("value", DataType::Long).or(DataType::Double)` is
`int|float $value`.
- `FunctionBuilder::or_returns(DataType)` does the same for the return type.
A class type in a union would need a type list and fails `build` with
`Error::ZvalConversion`. `FunctionHandler`, the type of the handler
`FunctionBuilder::new` takes, is exported from `builders`.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Review of the union support: - Union members go through `ZendType::scalar_type_mask`, the allowlist the typed properties use (`bool`, `int`, `float`, `string`, `array`, `object`), plus `null`. `.or(Resource)` and `.or(Undef)` gave the masks that crash `ReflectionType::__toString`, `.or(Reference)` and `.or(Ptr)` stray bits, `.or(Void)` and `.or(Mixed)` types PHP forbids, and `iterable` a bit only its own arginfo can carry; they now fail `build` with `Error::InvalidUnionType`, as does a class type. - A union on an `Arg::untyped` argument, and `or_returns` without `returns`, fail `build` instead of being dropped. - The docs say the handler must check its arguments (release builds do not check them against the declared types), and must return a value of the declared union (debug builds assert on it). Unit tests cover every `DataType` variant as a union member. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
LeakSanitizer reported the function name the test never registered. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ChiragAgg5k
force-pushed
the
feat/union-untyped-args
branch
from
November 23, 2026 12:33
16e99f1 to
52f04c2
Compare
Nightly rustfmt (2026-11-22) no longer breaks a line inside a markdown link, so tools/update_lib_docs.sh produced a different copy and the macro docs check failed.
ptondereau
approved these changes
Nov 25, 2026
Open
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
An internal function's parameter always gets a type:
Arg::newtakes a singleDataType, and the closest to PHP's untypedfunction f($value)ismixed. Union types can't be expressed at all; see #199, which this partly addresses.Reflection and PHP's inheritance checks see the difference. A PHP class whose method has an untyped parameter, or an
int|floatone, can't be reproduced. A port that needs it has to patch the engine's copy of the argument info after registration.Motivation: Appwrite is porting Utopia PHP libraries to Rust as classes of a PHP extension. Their base classes declare
isValid($value)untyped andint|floatparameters, and PHP subclasses in application code override them.Change
Arg::untyped(name)declares a parameter without a type:ReflectionParameter::hasType()isfalse, and overrides may declare any type or none.Arg::or(DataType)adds a member to a union:Arg::new("value", DataType::Long).or(DataType::Double)declaresint|float $value.FunctionBuilder::or_returns(DataType)does the same for the return type.Allowed members: the argument's type and every member go through
ZendType::scalar_type_mask(bool,int,float,string,array,object), plusnullfor a member.Refused, with the new
Error::InvalidUnionTypefrombuild:zend_type_list),iterable,resource,void,mixed,undef, a reference, a pointer, …;or_returnswithoutreturns.These are refused rather than producing masks PHP can't read, or being dropped silently.
FunctionHandlerexported: it's the type of the handlerFunctionBuilder::newtakes, and is now exported fromext_php_rs::builders.Size: the union is stored as
Option<Box<Vec<DataType>>>, under an explained#[expect(clippy::box_collection)].Argtravels inResult::Err(consume), so it has to stay underresult_large_err.Enforcement (documented)
These types are what reflection and the inheritance checks see:
: int|floatmust not returnnull, even on bad input.Tests
DataTypevariant as a union member, with its expected mask orInvalidUnionType;or_returnswithoutreturns;tests/src/integration/arg_types): reflection of untyped and union parameter and return types, plus a PHP subclass overriding abstract methods declared with them, which PHP's inheritance check accepts.types/functions.md.Future work
Stub generation (
describe::Parameter) holds a singleDataType: an untyped parameter is described with no type, a union as its first member. Describing unions needsdescribeto carry several types.🤖 Generated with Claude Code
Part of: appwrite-labs/cloud#7503