Skip to content

gh-2811: PHP8.4: New without parenthesis#2824

Merged
dantleech merged 1 commit intomasterfrom
gh-2811-new-no-paren
Jan 13, 2025
Merged

gh-2811: PHP8.4: New without parenthesis#2824
dantleech merged 1 commit intomasterfrom
gh-2811-new-no-paren

Conversation

@dantleech
Copy link
Copy Markdown
Collaborator

Fixes #2811

@dantleech dantleech force-pushed the gh-2811-new-no-paren branch 2 times, most recently from 464e5c9 to 6ecf6eb Compare January 13, 2025 20:21
@dantleech dantleech force-pushed the gh-2811-new-no-paren branch from 6ecf6eb to 79b7bfe Compare January 13, 2025 20:23
@dantleech dantleech merged commit 72dc7bb into master Jan 13, 2025
@dantleech dantleech deleted the gh-2811-new-no-paren branch January 13, 2025 22:03
@downhiller
Copy link
Copy Markdown

Am I being dumb dan? (Almost certainly). I've deleted my phpactor diretory, and its cache. Re-run git clone, composer install, phpactor index:build -reset. But in neovim using new without parentheses still comes up with an error ("Function foo not found") on the first method call after instantiation?

Thank you!

@dantleech
Copy link
Copy Markdown
Collaborator Author

you'll need to make sure you're on the master branch:

new Foo()
  ->bar()
  ->baz();

works for me (even on an 8.3 runtime, although I get parse errors from PHP itself)

@downhiller
Copy link
Copy Markdown

I am - checked with git branch, but master is the default when cloning from your repo anyway. Can you think of anything else it could be? Sorry!

@dantleech
Copy link
Copy Markdown
Collaborator Author

dantleech commented Feb 5, 2025

If you'd like to investigate copy this test case to a new file in the same dir:

lib/WorseReflection/Tests/Inference/new/new-no-parenthesis.test

and put your class structure and method call chain in there so that:

class Message
{
    public function setWarning(): self {}
    public function add(string $warning): self {}
    public function getrHtml(): string {}
}
wrAssertType('string', new Message()->setWarning()->addText('blah')->getHtml());

or whatever - then run

./vendor/bin/phpunit lib/WorseReflection/tests/Inference

to see if it works, and if it doesn't you could make an PR with the failing test.

@downhiller
Copy link
Copy Markdown

That does appear to pass. Though I don't understand, to me it looks like all it does is asserts that the return type of getHtml is string? 🤷‍♂️

Here's some very similar code in a new file with nothing else, showing the failure that I believe I'm having.

image

@dantleech
Copy link
Copy Markdown
Collaborator Author

dantleech commented Feb 6, 2025

well, if it asserts that it's a string then it's working. Are you sure these are Phpactor errors and not PHPStan ones (assuming you have phpstan installed and enabled the phpactor integration)? which PHP runtime are you using on your host?

@downhiller
Copy link
Copy Markdown

PHP 8.4.3

I was pretty sure that this message was coming from phpactor, I'll feel even more of a plum than normal if it's coming from phpstan. I think my phpstan only does anything when I manually run it from the commandline, and I think these errors were coming up before I even installed phpstan quite recently.

@downhiller
Copy link
Copy Markdown

If I add a line, thisDoesntExist(); to that file, and run phpstan on it, it correctly fingers that function as being missing, but doesn't say anything about setWarning(), so I'm 99% sure the message isn't coming from phpstan.

@downhiller
Copy link
Copy Markdown

downhiller commented Feb 6, 2025

well, if it asserts that it's a string then it's working. Are you sure these are Phpactor errors and not PHPStan ones (assuming you have phpstan installed and enabled the phpactor integration)? which PHP runtime are you using on your host?

I don't follow that logic? To my untrained eye all that means is that the code works in php (which I know it does), not that phpactor is happy with it and finding nothing to complain about? 🤷‍♂️

@dantleech
Copy link
Copy Markdown
Collaborator Author

dantleech commented Feb 6, 2025

that the code works in php

no, it's testing that phpactor evaluates the code statically, Phpactor is the interpreter here (f.e. there is no wrAssertType PHP function, it's internal to Phpactor's tests) 🙂 so if it determines that it's a string, then it correctly parsed and understood the methods. But it isn't to say there isn't a bug. But I can't see anything wrong on my end.

@downhiller
Copy link
Copy Markdown

Of course, I understand. I knew it was an internal function, but didn't quite process what was going on.

I don't know if this is useful, but if I run :lua vim.diagnostic.open_float() I get a minute amount more information:

Diagnostics:
1. Function "setWarning" not found [worse.unresolved_name]

Not sure if that clarifies where the message is coming from or not!

@downhiller
Copy link
Copy Markdown

Still having this issue, any further thoughts Dan? Thank you!

@downhiller
Copy link
Copy Markdown

OK, finally had time to look into this more. The issue is that I have two versions of phpactor installed. The one I've installed manually (dev-master) is NOT what neovim is loading in through Mason, which is stuck on 2024.11.28.1

I've tried to manually point Mason at the newer version, but can't seem to get it working and can't find (google/chatgpt) any concrete info on how to achieve this. I don't suppose you can either guide me, or release a new Tag?

Thank you Dan, as always ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

new MyClass()->method() without parentheses breaks parsing

2 participants