Bug 559657 - Validator warns about unresolved types when classes and namespaces have same name
Summary: Validator warns about unresolved types when classes and namespaces have same ...
Status: CLOSED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: PDT (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: PHP Core CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 559639
  Show dependency tree
 
Reported: 2020-01-29 05:58 EST by Thierry BLIND CLA
Modified: 2020-05-14 11:25 EDT (History)
1 user (show)

See Also:


Attachments
generated FFI classes (11.34 KB, application/octet-stream)
2020-01-29 06:00 EST, Thierry BLIND CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Thierry BLIND CLA 2020-01-29 05:58:37 EST
Hi,
while working on Bug 559639, I've fixed namespace declarations for the FFI classes.
But our validator cannot resolve FFI\CData and FFI\CType class usages.

I think our validator doesn't like classes and namespaces having same name.
I'm adding the file as attachement.
I know the file looks a bit strange, but it's content is valid and PDT should not warn about unresolved types.

Thierry.
Comment 1 Thierry BLIND CLA 2020-01-29 06:00:20 EST
Created attachment 281640 [details]
generated FFI classes
Comment 2 Eclipse Genie CLA 2020-05-03 11:42:12 EDT
New Gerrit change created: https://git.eclipse.org/r/161940
Comment 3 Thierry BLIND CLA 2020-05-03 16:33:16 EDT
Hi,
after doing some debugging, I think I found some (hopefully) very uncommon cases that PDT handles wrongly.
Take following example:

<?php
namespace {
final class FFI  {
	/**
	 * @return bool whether a \FFI\CData is a null pointer.
	 */
	public static function isNull (\FFI\CData &$ptr) {}
}
}

namespace FFI {
final class CData  {
}
}

For now, in PHPIndexingVisitor#visit(TypeDeclaration),
PDT will first (correctly) detect the \FFI (non-namespace) type in the global namespaceand after that will detect the \FFI namespace type but will wrongly share same "index occurence count" for both detected types.
In this very specific case, it's necessary to have different "index occurence counts", otherwise PHPElementResolver#resolve() will generate exactly same IndexType(parentElement, elementName, ..., occurrenceCount) for 2 very different element types (i.e. IModelElement.PACKAGE_DECLARATION and IModelElement.TYPE) and "bind" them together!

Same problem occurs when there is first a \FFI namespace type and then a \FFI (non-namespace) type inside a global namespace:

<?php
namespace FFI
{
}
namespace
{
    final class FFI
    {
        /**
         *
         * @param \FFI\CData $ptr
         *            The handle of the pointer to a C data structure.
         */
        public static function isNull(\FFI\CData &$ptr)
        {
        }
    }
}
namespace FFI
{
    final class CData
    {
    }
}

https://git.eclipse.org/r/#/c/161940/ should address this issue.

Thierry.
Comment 5 Thierry BLIND CLA 2020-05-04 17:30:29 EDT
Fixed.