Community
Participate
Working Groups
Example: /** * @return ArrayAccess|DateTime[] */ function foo() { return ""; } Type inference detect: AmbigousType: PHPClass: ArrayAccess MultyTypyType: DateTime And it's correct, unfortunately code assist is incorrect: foo()->| // <- I expect ArrayAccess functions, see mix foo()[0]->| <- I expect Datetime functions, see mix foo()[0][0]->| // < I expect empty result, see mix foreach (foo() as $item) { $item->| //<- I expect datetime functions } Another simpler example: /** * @return DateTime[] */ function foo() { return ""; } foo()->| // <- I expect empty , see datetime foo()[0]->| <- I expect Datetime functions foo()[0][0]->| // < I expect empty result, see datetime We fixed in past ArrayAccess AST for fields, so in theory should be simple to improve this.
I'll add also another problem I've seen with arrays having such kind of indexes: $myArrayOfDateTime[count($myArrayOfDateTime) - 1]->| will return no datetime methods :(
(In reply to Thierry BLIND from comment #1) > I'll add also another problem I've seen with arrays having such kind of > indexes: > > $myArrayOfDateTime[count($myArrayOfDateTime) - 1]->| > > will return no datetime methods :( This is different issue. Our parser isn't as good as JDT parser on Error-Recovery level. Due this CA trying to detect what you have before cursor and interpret this (wrongly this time). This is also introduces unnecessary complexity and code duplications (inferring before cursor vs inferring normal AST).
(In reply to Dawid Pakula from comment #2) > (In reply to Thierry BLIND from comment #1) > > I'll add also another problem I've seen with arrays having such kind of > > indexes: > > > > $myArrayOfDateTime[count($myArrayOfDateTime) - 1]->| > > > > will return no datetime methods :( > > This is different issue. > > Our parser isn't as good as JDT parser on Error-Recovery level. Due this CA > trying to detect what you have before cursor and interpret this (wrongly > this time). This is also introduces unnecessary complexity and code > duplications (inferring before cursor vs inferring normal AST). ok thank you for the answer, Dawid :) You mean we should de-duplicate and only use (for example) normal AST by doing better error recovery (and no code to detect parenthesis, brackets,... in text)? so build better partial AST nodes tree?