Add callable type to PHP
ClosedPublic

Authored by mtijink on Aug 1 2017, 1:01 PM.

Details

Summary

This diff adds a new primitive callable type to the PHP language support. This represents anything which can be called as a function in PHP (e.g. a function name as string, a closure, an array with two entries for static class methods, etc.).

Additionally, for return types, when two return types are detected with one being a callable and one an actual function, the return type is set to just a callable.

Diff Detail

Repository
R52 KDevelop: PHP Support
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
mtijink created this revision.Aug 1 2017, 1:01 PM
Restricted Application added a subscriber: kdevelop-devel. · View Herald TranscriptAug 1 2017, 1:01 PM
zhigalin requested changes to this revision.Aug 1 2017, 6:24 PM
zhigalin added a subscriber: zhigalin.

Rest LGTM

duchain/tests/duchain.cpp
751

For return $i(); the return type should be mixed, not callable

This revision now requires changes to proceed.Aug 1 2017, 6:24 PM
mtijink added inline comments.Aug 1 2017, 9:41 PM
duchain/tests/duchain.cpp
751

Both return statements return a callable: $i (note: without ()) is a callable, and function () {} is a callable too. So I think this behaviour is correct, but correct me if I'm wrong.

zhigalin added inline comments.Aug 1 2017, 9:47 PM
duchain/tests/duchain.cpp
751

The problem arises then you return the result of calling $i() and the parser still think you're returning a callable

mtijink added inline comments.Aug 1 2017, 10:00 PM
duchain/tests/duchain.cpp
751

Ah ok, you're correct. But that's not due to a problem in this code, but problems in the ExpressionVisitor: it skips most operators, such that the resulting type is that of the last appearing variable/literal. Thus, it applies the type of $i instead of the result of calling the function.

For example, function foo() { $i = function () {}; return $i(); } yields type void () foo (), which also is incorrect.

zhigalin accepted this revision.Aug 2 2017, 9:11 AM
zhigalin added inline comments.
duchain/tests/duchain.cpp
751

Okay then, commiting

This revision is now accepted and ready to land.Aug 2 2017, 9:11 AM
This revision was automatically updated to reflect the committed changes.