Bug 549197 - Validator gets confused when a class alias matches the same name as a used trait
Summary: Validator gets confused when a class alias matches the same name as a used trait
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: PHP Core CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-07-11 20:22 EDT by Claudio Luis CLA
Modified: 2020-05-14 10:16 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Claudio Luis CLA 2019-07-11 20:22:09 EDT
Consider the following example, consisting of an interface, a trait and a class:

+-- Interface ----------------------------+
| interface I                             |
| {                                       |
|     public function makeStuff(): void;  |
| }                                       |
+-----------------------------------------+

+-- Trait --------------------------------+
| namespace Traits;                       |
|                                         |
| trait StuffMaker                        |
| {                                       |
|     public function makeStuff(): void   |
|     {                                   |
|         //code                          |
|     }                                   |
| }                                       |
+-----------------------------------------+

+-- Class --------------------------------+
| use stdClass as StuffMaker;             |
|                                         |
| class A implements I                    |
| {                                       |
|     use Traits\StuffMaker;              |
| }                                       |
+-----------------------------------------+

The above is syntactically correct, without any reference conflicts of any kind, and executes without a problem, however the PDT validator reports a problem in class A claiming:
"The type A must implement the inherited abstract method I::makeStuff()"

This error disappears if I either comment out the "use stdClass as StuffMaker" line, or if I change the alias itself, such as to "use stdClass as FooMaker".

It seems that for some reason the validator gets confused by the name of the trait being the same as the name given in the alias, although "StuffMaker" and "Traits\StuffMaker" reference completely different things.

This seems to happen at least since the Oxygen version of Eclipse(the oldest version I tested, and where I first noticed the problem), as well in the newest nightly version, both in Linux (Ubuntu) and Windows 10.
Comment 1 Eclipse Genie CLA 2019-07-15 13:26:28 EDT
New Gerrit change created: https://git.eclipse.org/r/146105
Comment 3 Thierry BLIND CLA 2019-07-16 11:25:31 EDT
Fixed.

Claudio, could you give a try to upcoming PDT nightly version to confirm me that your problems are solved?

Thank you!
Thierry.
Comment 4 Claudio Luis CLA 2019-07-16 16:36:38 EDT
Yes, just updated, it's been fixed. :)

Although, now there seems to be another problem: when using the PHP 7.2 validator, it seems to not detect the existence of some global namespace interfaces and classes, such as Countable, JsonSerializable and ReflectionClass, with the "The import ReflectionClass cannot be resolved" error, although in the Core API directory set up by PDT all the files and declarations are there, none of them are missing, which is strange.

However other global interfaces such as ArrayAccess and classes such as Exception are detected without issues.

Changing to the PHP 7.3 validator however, works flawlessly.

Changing back to the PHP 7.2, the issues appear again, and changing back to PHP 7.3, the issues disappear, so it's always reproducible on my end at least, even across different projects.

Unfortunately, I cannot remember at 100% if it was already this way before or only after this specific update, so I cannot accurately pinpoint when this started to happen, so I may try to reproduce the problem in more detail later, and create another separate bug report for it.

Thank you very much! :)
Comment 5 Thierry BLIND CLA 2019-07-16 18:28:00 EDT
Hi Claudio,
yes, it's better to create a separate bug report, so we can continue our discussion there.
For me it's another unrelated problem, it would be nice if you could create a little demo project to reproduce the problem.

For me, validation problems can often be solved by doing Project -> Clean... and rebuilding the problematic project. Have you tried that?
Is your "Project -> Build Automatically" option also checked?

Thierry.
Comment 6 Thierry BLIND CLA 2019-07-16 19:16:16 EDT
And please make also some tests with your older eclipse oxygen version (so without this patch applied), to confirm that your "php version switching bug" was already present.
Comment 7 Claudio Luis CLA 2019-07-16 19:53:24 EDT
Yes, Project -> Clean is actually something I always do after any major change, from updates in Eclipse to after installing or updating PHP dependencies (through Composer), and in a few other situations, which solves most problems from the get-go.

Sometimes I also press F5 before a Clean so that everything is refreshed and synced up with what's actually saved on disk.

And yes, my projects are set to build automatically as well.

In the Oxygen version I am sure it's OK, but the PDT version itself is quite outdated I believe, which after confirming I can update to the latest nightly corresponding to Oxygen to check if the problem appears.

Since it also sits in a different machine with a different OS, I will attempt to download and test the newer Eclipse version there, but without the nightly at first to check if the problem was already present before the nightly at least.

Either way, I will indeed investigate the problem in more detail to try to provide more specific information in a different bug report, that is, if this doesn't end up being simply a problem on my own end. :)

Thank you. :)