Tyhp 805.1.2-beta.4 #6
pristinesource
announced in
Announcements
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Tyhp 805.1.2-beta.4 is out. Emitted PHP can carry PHPStan and Psalm docblocks, a
.tyhpfile 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"inrequire-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
Added
@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..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.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.#[\Tyhp\PropertyType('…')], which\Tyhp\Type::fromProperty()reads.App\Table<App\Blog>,struct App\Address) instead of the erased class name.\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."api/{$resource}/items"can be returned as"api/${string}/items".T extends string,T extends 'a'|'b') can be interpolated, concatenated, echoed, and used as template holes.Changed
?->.?->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.$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.${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.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.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.__toString,__get,__set,__isset,__unset,__destruct,__clone,__serialize,__unserialize,__sleep,__wakeup,__set_state), not just__construct, and names the method.__debugInfo()on an enum whenoutput.phpVersionis below 8.6.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.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).public(set)are not reported.readonly class, which PHP rejects when the class loads.Fixed
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.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.<?=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..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.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.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.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.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.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.__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.build.updateComposercannot read a runtime package's owncomposer.json, it pinstyhp/*0.4(80N.0.4) andtyhpdef/php0.0.3instead of0.1and0.0.1.readonly classthat uses a trait with a non-readonly instance property or a static property now reports TYHP4380 whenoutput.phpVersionis 8.2 or newer. PHP rejects that class when it loads.All reactions