fix(preprocessor): validate compound type declarations and class-scope type keywords - #65
Open
AlessioGiacobbe wants to merge 2 commits into
Open
Conversation
…e type keywords
resolveTypeDecl now runs a shared well-formedness pass before resolving,
so parameters, returns, properties, class/interface constants, and
closure signatures all obey Zend's compile-time compound-type rules
(each probed on 8.4.13):
- duplicate union members, case-insensitive and after alias/namespace
resolution ("Duplicate type int is redundant", "Duplicate type
App\Sub\Thing is redundant"); iterable is expanded to
array|Traversable first, so iterable|array and iterable|\Traversable
report the overlapping component exactly like Zend, while a
namespace-local Traversable stays legal
- bool with false/true names the literal as the duplicate in either
order; true|false demands bool ("Type contains both true and false,
bool must be used instead")
- mixed/void/never inside a union ("... can only be used as a
standalone type"), ?mixed ("Type mixed cannot be marked as nullable
since mixed already includes null"), ?null, ?void, ?never
- intersection members must be class types ("Type int cannot be part
of an intersection type"); duplicate intersection members are
redundant; self/parent/static keep the established TypeCheckGenerator
diagnostic; redundancy between whole DNF groups is not checked (Zend
uses a distinct "Type X&Y is redundant with type X&Y" pass)
- self/static return types on free functions ("Cannot use \"static\"
when no class scope is active"); closures keep accepting them since
they may be bound to a scope later, matching Zend
- duplicate interfaces in an implements list, for classes and enums
("Class A cannot implement previously implemented interface I");
duplicate trait use stays legal - Zend deduplicates it silently
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.
Compound type declarations were not validated for well-formedness — all of these compiled, each a Zend compile fatal (probed individually): duplicate union members after alias/namespace resolution (
int|string|int,Foo|\Foo, iterable expanded soiterable|arraynames the overlapping component); bool/true/false overlaps (bool|false,true|false→ "bool must be used instead");mixed/void/neverinside unions;?mixed,?null,?void,?never; non-class standard types and duplicates inside intersections;self/staticreturn types outside class scope (closures exempt, as Zend compiles them); duplicateimplementsentries for classes and enums.One validation helper runs from a resolveTypeDecl override, so parameters, returns, properties, constants, and closures share the same pass without double-firing.
use T, Tis deliberately still accepted — Zend silently dedupes trait use (probed).Part of the split of #39.