@@ -168,19 +168,84 @@ function justContainsInlineHtml()
168168/** @phpstan-pure */
169169function bug13288 (array $ a )
170170{
171- array_push ($ a , function () { // error because by ref arg
171+ array_push ($ a , function () { // error because by ref arg
172172 exit (); // ok, as array_push() will not invoke the function
173173 });
174174
175175 array_push ($ a , // error because by ref arg
176176 fn () => exit () // ok, as array_push() will not invoke the function
177177 );
178178
179- $ closure = function () {
179+ $ exitingClosure = function () {
180180 exit ();
181181 };
182182 array_push ($ a , // error because by ref arg
183- $ closure // ok, as array_push() will not invoke the function
183+ $ exitingClosure // ok, as array_push() will not invoke the function
184184 );
185+
186+ takesString ("exit " ); // ok, as the maybe callable type string is not typed with immediately-invoked-callable
187+ }
188+
189+ /** @phpstan-pure */
190+ function takesString (string $ s ) {
191+ }
192+
193+ /** @phpstan-pure */
194+ function bug13288b ()
195+ {
196+ $ exitingClosure = function () {
197+ exit ();
198+ };
199+
200+ takesMixed ($ exitingClosure ); // error because immediately invoked
201+ }
202+
203+ /**
204+ * @phpstan-pure
205+ * @param-immediately-invoked-callable $m
206+ */
207+ function takesMixed (mixed $ m ) {
208+ }
209+
210+ /** @phpstan-pure */
211+ function bug13288c ()
212+ {
213+ $ exitingClosure = function () {
214+ exit ();
215+ };
216+
217+ takesMaybeCallable ($ exitingClosure );
218+ }
219+
220+ /** @phpstan-pure */
221+ function takesMaybeCallable (?callable $ c ) { // arguments passed to functions are considered "immediately called" by default
222+ }
223+
224+ /** @phpstan-pure */
225+ function bug13288d ()
226+ {
227+ $ exitingClosure = function () {
228+ exit ();
229+ };
230+ takesMaybeCallable2 ($ exitingClosure );
231+ }
232+
233+ /** @phpstan-pure */
234+ function takesMaybeCallable2 (?\Closure $ c ) { // Closures are considered "immediately called"
235+ }
236+
237+ /** @phpstan-pure */
238+ function bug13288e (MyClass $ m )
239+ {
240+ $ exitingClosure = function () {
241+ exit ();
242+ };
243+ $ m ->takesMaybeCallable ($ exitingClosure );
244+ }
245+
246+ class MyClass {
247+ /** @phpstan-pure */
248+ function takesMaybeCallable (?callable $ c ) { // arguments passed to methods are considered "later called" by default
249+ }
185250}
186251
0 commit comments