Skip to content

Result in syntax error when serializing instanceof {expression} #104

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: 2.x
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/ReflectionClosure6Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

use Foo\Bar as Baz;
use Foo\Baz\Qux;
use Foo\Baz\Qux\Forest;
use Laravel\SerializableClosure\Support\ReflectionClosure;
use Tests\Fixtures\Model;
use Tests\Fixtures\RegularClass;

test('resolve instanceof with expression', function () {
$f1 = fn (Baz $a) => $this instanceof (Forest::class); // Turning `instanceof` into an expression results into this incorrect compilation
$e1 = 'fn (\Foo\Bar $a) => $this instanceof (\Foo\Baz\Qux\Forest::class)';

$f2 = fn (Baz $a) => $this instanceof (class_exists(Foo::class) ? Foo::class : Forest::class);
$e2 = 'fn (\Foo\Bar $a) => $this instanceof (class_exists(\Foo:class) ? \Foo::class : \Foo\Baz\Qux\Forest::class)';

expect($f1)->toBeCode($e1);
expect($f2)->toBeCode($e2);
});
Loading