pdt icon indicating copy to clipboard operation
pdt copied to clipboard

Short arrow closure syntax gives warnings with function args

Open pounard opened this issue 5 years ago • 1 comments

Hello ! Since 2020-03 and then still present in 2020-06 when I write a closure using short arrow syntax (PHP >= 7.4), closure arguments raise a Variable {$foo} is undefined warning.

Version is:

Eclipse IDE for PHP Developers (includes Incubating components)
Version: 2020-06 (4.16.0)
Build id: 20200615-1200

I have quite a few addons installed, but I noticed the bug prior to installing it.

  • OS: Running ArchLinux, uname output: Linux guinevere 5.7.6-arch1-1 #1 SMP PREEMPT Thu, 25 Jun 2020 00:14:47 +0000 x86_64 GNU/Linux

Steps to reproduce the behavior:

  1. Open a PHP file,
  2. Write a short arrow syntax closure with at least one argument.

A few screenshots following.

20200703-EclipsePDTWarningInSASC-1

20200703-EclipsePDTWarningInSASC-2

OK that's not really visible, but notice the yellow underline on the closure parameter name, then at its usage.

pounard avatar Jul 03 '20 07:07 pounard

Hi,

I'm having this warning too Eclipse PDT 8.0.0.202007171531 (@fedora 34)

quazardous avatar Jun 05 '21 05:06 quazardous

Hi, Bug always present in PHP Development Tools (PDT) 8.0.0.202112011911

lpotherat avatar Jan 02 '23 13:01 lpotherat

@zulus I updated this morning, I'm now running version 8.1.0.202306071122 and I'm still experiencing this bug.

pounard avatar Jun 09 '23 09:06 pounard

@pounard Can you post example code?

zulus avatar Jun 09 '23 09:06 zulus

First one found in my currently opened project (sorry it's french domain code):

    /**
     * Récupère le ou les destinataires des contacts entreprise de la demande.
     *
     * @return Destinataire[]
     */
    public function getEntrepriseDestinataireAll(): array
    {
        return \array_filter(
            \array_map(
                fn (Contact $contact) => $contact->email ? new Destinataire((string) $contact->id, $contact->email) : null,
                $this->getEntrepriseContactAll()
            )
        );
    }

Here the $contact variable inside the closure body is yellow underlined with the following message on hover:

Variable '$contact' is undefined

By the way, it also yellow underlines the null keyword, also the (string) cast, without any other message that the given one (I think it's underlining the whole line actually, but yellow on white is barely visible, I have to change that color setting).

Here is a screenshot:

Capture d’écran du 2023-06-09 12-09-13

Sorry, I can't really screenshot the tooltip...

pounard avatar Jun 09 '23 10:06 pounard

Forgot to mention: PHP validation for this project is configured to PHP 8.0, fun fact, when switching to PHP 8.2, I don't have warnings in most case, except this one, see:

Capture d’écran du 2023-06-09 12-13-46

Now, only the part in new Destinataire((string) $contact->id, $contact->email is underlined as being an warning, the rest is fine.

So there are two bugs here:

  • first, it works with PHP 8.2 parser, but not previous ones (although I didn't tested using PHP 8.1, this project is kind huge to validate),
  • now that it works in 90% percent of use cases, there are still some pitfalls in 8.2 parser.

Validation message is still the same:

Variable '$contact' is undefined

pounard avatar Jun 09 '23 10:06 pounard

Arghh! I completely forgot about tenary operator changes in PHP 8, is no longer left associative. So it’s not problem in validator (works correctly), but in php 8 parser, it produce wrong AST. Separate task will be needed. Can you prepare? If not I’ll do it at night

zulus avatar Jun 09 '23 13:06 zulus

Can you prepare?

I'm sure to understand the question here ?

pounard avatar Jun 09 '23 13:06 pounard