The following PHP code crashes KDevelop: <?php $a = new A(); $a->x = 1; class A { var $x = 1; } Crash occurs at declarationbuilder.cpp:441: Declaration *dec = currentContext()->parentContext()->findDeclarationAt(startPos(node)); This line belongs to the fix for bug 241750. Using parentContext() is incorrect, because it's NULL outside the class body, which leads to a crash. Moreover, the following code still produces a "cannot redeclare" warning for me at "var $a = 1" line, so bug 241750 should probably be reopened: <?php class T { } class B { function x() { $this->a = 1; } var $a = 1; }
Created attachment 69625 [details] My patch for this bug hooray =) I've succeeded in fixing this bug by myself - see the patch. Fixes both described cases (crash and redeclaration warning).
Created attachment 69627 [details] Even simpler patch May be even simpler, without localScopeIdentifier(). The performance will be better without it, am I right?
An even the first change could be also removed from the simpler patch (because it's identical). Or was it intentional to use identifierPairForNode?
Git commit 6e75a811fc4d2be58f56a56a1dcd1d818b5b024f by Milian Wolff. Committed on 15/03/2012 at 23:58. Pushed by mwolff into branch '1.3'. properly check context before accessing it M +6 -5 duchain/builders/declarationbuilder.cpp M +46 -0 duchain/tests/duchain.cpp M +1 -0 duchain/tests/duchain.h M +5 -2 duchain/tests/duchaintestbase.cpp M +3 -1 duchain/tests/duchaintestbase.h http://commits.kde.org/kdev-php/6e75a811fc4d2be58f56a56a1dcd1d818b5b024f
Sorry Vitaliy, I've had this patch on my box for some days but forgot to push it. Please take a look at it, and esp. how to write unit tests. If you find more issues in the future and want to help with development, it would be really cool if you could write a unit test. That is already more than 50% of the work to fix a bug most often! Anyhow, this should now be fixed.
and I'll now look into the false-positive warning issue
I have a question about your patch: is it ok to use currentContext as current class context? Or is it better to use parentCtx? --- False-positive warning issue is very simple to fix, look at my patch... Now, visitClassDeclarationStatement() calls m_upcomingClassVariables.clear(). This apparently happens after first class declaration, so when looking at other class declarations, m_upcomingClassVariables is empty, and declarations are not invalidated.
Also, a question about 1.3 and master branches: which of them is newer? (you committed the fix to 1.3, so the development process happens there, not in master?)
And one more: with your patch, the following code: <?php $x = new A(); $x->y = 1; $x->y = 2; class A { } moves $x->y declaration to the second line, not the first one. Is this supposed to be so, or the declaration is supposed to be the first occurrence?
ok I'll take another look at your patch. regarding branches: bug fixes should go to 1.3 and then get merged into master (I just did that). and of course: the first use of $this->y should be the declaration, i.e. yet another bug -> please open another bug report!
The crash is gone, changing title and status.
Git commit 42d3c0e577e2e4168a4e87d8ab9deceb8e692fd3 by Heinz Wiesinger. Committed on 17/08/2018 at 15:08. Pushed by wiesinger into branch '5.3'. Improved type detection for object properties. Summary: This should solve long standing bugs that make kdev-php difficult to use with common PHP frameworks. * Properly resolve namespaced identifiers for type information in the phpdoc block * Default type for class properties without assigned value is now NULL instead of 'mixed' (if no other type is specified in the phpdoc block) * The NULL type is replaced on first assignment to the property. Related: bug 241750 FIXED-IN: 5.3.0 Reviewers: brauch Reviewed By: brauch Subscribers: brauch, kdevelop-devel Tags: #kdevelop Differential Revision: https://phabricator.kde.org/D14876 M +92 -26 duchain/builders/declarationbuilder.cpp M +14 -3 duchain/builders/typebuilder.cpp M +10 -2 duchain/expressionvisitor.cpp M +97 -11 duchain/tests/duchain.cpp M +2 -0 duchain/tests/duchain.h M +16 -0 duchain/tests/uses.cpp M +1 -0 duchain/tests/uses.h https://commits.kde.org/kdev-php/42d3c0e577e2e4168a4e87d8ab9deceb8e692fd3