Repository navigation
Releases
Releases · tyhpproject/tyhp
tyhp v805.1.2-beta.4
Tyhp 805.1.2-beta.4 is out. Emitted PHP can carry PHPStan and Psalm docblocks, a .tyhp file treats <?= as a Tyhp echo, and expression trees accept nested arrow functions, array literals, and ?-> calls.
This is a public beta. Syntax may still change.
Install
curl -fsSL https://raw.githubusercontent.com/tyhpproject/tyhp/main/scripts/install.sh | bash -s --Composer projects: "tyhp/compiler": "805.1.2-beta.4" in require-dev, with "minimum-stability": "beta".
Docs: https://tyhplang.com · Release notes: https://tyhplang.com/release_prevList.html · GitHub: https://github.com/tyhpproject/tyhp/releases/tag/v805.1.2-beta.4
Comments: https://github.com/orgs/tyhpproject/discussions/6
Added
- Emitted PHP includes PHPStan/Psalm docblock tags (
@param,@return,@var,@template,@extends,@implements,@internal) where the PHP declaration drops type information.emit.docblocksdefaults tolossy-onlyin every build profile;allemits a tag for every signature type andoffemits none.emit.docblockDialectdefaults toboth. Author docblocks and emitter directives are kept;output.comments: falsedrops prose and keeps analysis tags. - In a
.tyhpfile,<?=is a Tyhp echo. The expression list is parsed and checked as Tyhp (is,typeof,with, andnameofare keywords) and emitted asecho, with the same stringable rules asecho(TYHP4120). The output is not escaped. A.phpfile still treats<?=as a PHP echo. - Expression trees accept nested arrow
fnbodies (asLambdaExpressionnodes), list and keyed array literals, and?->method calls. Array spread is rejected with TYHP4322. PropertyPath<callable(T): R>parameters infer a genericRfrom an inlinefn, also in a union withcallable(T): R; a?->chain makesRnullable.- Emitted properties and promoted constructor parameters whose PHP hint loses type information (type arguments, struct types, source type aliases) carry
#[\Tyhp\PropertyType('…')], which\Tyhp\Type::fromProperty()reads. - Expression-tree parameter nodes carry the full declared type (
App\Table<App\Blog>,struct App\Address) instead of the erased class name. - More narrowing forms:
\assert($cond);, loose!= null/<>/== null(non-null side only), nested property paths ($a->b->c), static properties of any class, andswitch (true)/match (true)arms, which see earlier conditions as false. - Template string holes can name type aliases (imported, namespace-qualified, class-level, generic, or from a tyhpdef), so template aliases compose. An unknown hole name reports TYHP3003 and a self-referencing alias TYHP3029.
- A double-quoted interpolation whose text and hole types fit a template string type is assignable to it, so
"api/{$resource}/items"can be returned as"api/${string}/items". - Type parameters constrained to stringable types (
T extends string,T extends 'a'|'b') can be interpolated, concatenated, echoed, and used as template holes.
Changed
- New error TYHP4198 for reading or writing a property, calling a method, or indexing through a possibly null receiver without narrowing it first. Code that compiled before may now fail; narrow the value or use
?->. - A value read through
?->is nullable ($a?->bis?B), so using it where a non-null value is required now reports an error. Later links in the same chain short-circuit as in PHP. - Expression trees reject a variable method name (
$x->$m()), a class held in a variable (new $c(),$c::make(),$x::class), named arguments, and argument unpacking with TYHP4322. These were accepted before and emitted incorrectly. - New error TYHP4199 for a template string hole with no string form (
${bool},${array}) or written as an expression (${$x}, an inline nested template). .and.=report TYHP4120 for operands with no string form, such as arrays and unconstrained type parameters. Nullable stringable operands are allowed.- String interpolation, heredoc holes,
echo, andprintaccept nullable stringable values (?string,?int, a nullable class with__toString), like.does;nullbecomes''. In a template string type, a nullable hole fits only a hole that also allows empty text, so"item-{$id}"with?int $idfits"item-${''|int}"but not"item-${int}". ${int}and${float}template holes match only the text PHP's(string)cast produces:${int}accepts'3'but not'03'or'+3'.breakinside a closure that is nested in a loop is now rejected.- New error TYHP4378 for a default value on a readonly property (or any instance property of a
readonly class) whenoutput.phpVersionis below 8.6, which PHP rejects when the class loads. Assign the value in the constructor or use a promoted parameter default. - TYHP4024 now reports every magic method PHP rejects on an enum (
__toString,__get,__set,__isset,__unset,__destruct,__clone,__serialize,__unserialize,__sleep,__wakeup,__set_state), not just__construct, and names the method. - New error TYHP4379 for
__debugInfo()on an enum whenoutput.phpVersionis below 8.6. - With
build.updateComposer, a target PHP version that has no publishedtyhp/*runtime release (such as8.0or8.1) reports TYHP7108 and leavescomposer.jsonunchanged, instead of pinning804.X.Ypackages that need PHP 8.4. scripts/release.shtakesprerelease,alpha,beta,rc,release,patch,minor,major, or an explicitX.Y.Z. It publishes the GitHub Release only after each asset matchesdist/checksums.txt, and it checks the bundled runtime versions against the runtime checkout.- Every instance property and promoted constructor parameter of a
readonly classis now readonly, as in PHP, so all readonly checks apply to it: writing it through another object or from outside the class (TYHP4021), a hook on it (TYHP4155), andwithon it (TYHP4139–TYHP4141, TYHP4400, TYHP4401). - TYHP4021 now also reports writes to a readonly property from a function, the file scope, or a class other than the declaring class or a subclass. Properties with an explicit set visibility such as
public(set)are not reported. - New error TYHP4109 for a static property in a
readonly class, which PHP rejects when the class loads.
Fixed
- A runtime-tracked generic
readonly classemits an instance\Tyhp\GenericObject $__tyhpGenericproperty with no default, initialized by__bootGenericBag__tyhpGeneric(), instead of theHasGenericstrait, so the class loads on PHP 8.2 and later andclonekeeps the tracked types. A generic class that is not readonly still uses the trait. - Readonly
new … withbelow PHP 8.3 reports TYHP4400 instead of emitting a__clonewrapper that PHP 8.2 rejects.clone … withon areadonly classbelow PHP 8.5 reports TYHP4401. Experimentalclone … withon PHP 8.3–8.4, for a class that is not readonly, emits a wrapper that loads: the empty constructor has no return type, it does not call the parent constructor with no arguments, and overrides sit on a static stack. - Inline HTML and
<?=echoes in a.tyhpfile stay in source order, including inside a function or control-flow block, and a later<?tyhpsection is accepted.<?tyhp ?>or<?tyhp?>opens an empty section. A<?phpblock in a.tyhpfile reports TYHP2005. In a tagless project, the first six characters choose the file:<?tyhpis a tagged template, and any other.tyhpfile is tagless code with no open tag, so<?tyhpthere is not accepted. - Inline HTML in a
.tyhpfile is emitted exactly as written: the emitted PHP no longer indents HTML lines (which printed extra spaces, including inside closures), and a blank line right after?>is kept. - An
fnthe emitter could not turn into an expression tree was silently emitted as a plain closure; it now reports TYHP5024. $a ?: $bin an expression tree emitted anulltrue branch, and a nestedfnpassed to aPropertyPathparameter inside a tree was emitted as a plain closure.- A
switchwith adefaultcase where every case returns or throws no longer reports TYHP4011, and code after it reports TYHP4012. break 2/continue 2from aswitchinside a loop no longer reports TYHP4026, and a loop's exit now accounts for the state at eachbreakandcontinue.- An
ifarm that returns, throws, breaks, or continues now leaves only the other arm's narrowing after theif, and a write to a narrowed path inside a nested block ends that narrowing. <>was typedunresolved(TYHP4043); it now works like!=.EventLoop::runaccepts aPromise<void>, so anasyncfunction declared: voidcan be run from synchronous code.- Extension methods on a union target resolve when called from inside a namespace.
- A
catchthat always throws or returns no longer makes locals assigned in thetry"possibly undefined" (TYHP4014). \get_object_vars()on a concrete object no longer reports TYHP4035.- Generated tyhpdefs keep a template string type's pattern and fully qualify alias names in its holes, so a library's consumers see the same type.
- A property or promoted constructor parameter in a
readonly classwithout its ownreadonlyno longer reports TYHP4108, which is retired. new … withon areadonly classon PHP 8.3–8.4 emitsnew readonly class, because a non-readonly class cannot extend a readonly class.- Concatenating a nullable class that has
__toString(?Name . 'x') no longer reports TYHP4029. tyhp --explainhas long-form text again for about 20 codes (including TYHP3031–TYHP3035 and TYHP4373–TYHP4377), and keeps Markdown list items on separate lines.- When
build.updateComposercannot read a runtime package's owncomposer.json, it pinstyhp/*0.4(80N.0.4) andtyhpdef/php0.0.3instead of0.1and0.0.1. - A
readonly classthat uses a trait with a non-readonly instance property or a static property now ...
tyhp v805.1.2-beta.3
tyhp v805.1.1-beta.3
tyhp v805.1.0-beta.3
tyhp v805.1.0-beta.2
tyhp v805.1.0-beta.1
What's Changed
- tier 2 by @pristinesource in #1
- cleaned up some warnings by @pristinesource in #2
New Contributors
- @pristinesource made their first contribution in #1
Full Changelog: v805.0.0-alpha.1...v805.1.0-beta.1