[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    playground/devtools/kdevelop4-extra-plugins/php/duchain
From:       Milian Wolff <mail () milianw ! de>
Date:       2009-05-22 13:27:11
Message-ID: 1242998831.854511.17869.nullmailer () svn ! kde ! org
[Download RAW message or body]

SVN commit 971457 by mwolff:

report an error if the user tries to redeclare $this in a class-context


 M  +4 -5      declarationbuilder.cpp  
 M  +15 -0     tests/test_duchain.cpp  
 M  +1 -0      tests/test_duchain.h  


--- trunk/playground/devtools/kdevelop4-extra-plugins/php/duchain/declarationbuilder.cpp \
#971456:971457 @@ -501,11 +501,10 @@
         } else {
             // assigment to other variables
             QualifiedIdentifier identifier = \
                identifierForNode(lastVariableIdentifier);
-            if (identifier == QualifiedIdentifier("this")) {
-                // TODO: we cannot assign anything to $this, but we are currently \
                not in the position
-                //       to decide whether we are really assigning to $this and are \
                not using something
-                //       like $this->foo[$bar] = ...
-                //       => we really need better support for arrays here I think...
+            if ( identifier == QualifiedIdentifier("this")
+                 && currentContext()->parentContext()
+                 && currentContext()->parentContext()->type() == DUContext::Class ) \
{ +                reportError(i18n("Cannot re-assign $this."), QList<AstNode*>() << \
node << lastVariableIdentifier);  return;
             }
 
--- trunk/playground/devtools/kdevelop4-extra-plugins/php/duchain/tests/test_duchain.cpp \
#971456:971457 @@ -1628,6 +1628,21 @@
     QCOMPARE(top->problems().count(), 0);
 }
 
+void TestDUChain::testThisRedeclaration()
+{
+    //               0         1         2         3         4         5         6   \
7 +    //               \
01234567890123456789012345678901234567890123456789012345678901234567890123456789 +    \
QByteArray code("<? class foo{ function foo(){ $this->test = true; $this = false;} \
}"); +    TopDUContext* top = parse(code, DumpAST);
+    DUChainReleaser releaseTop(top);
+    DUChainWriteLocker lock(DUChain::lock());
+
+    // only $this = false is a problem, $this->test = true is perfectly valid
+    QCOMPARE(top->problems().count(), 1);
+    kDebug() << top->problems().first()->finalLocation();
+    QVERIFY(top->problems().first()->finalLocation() == KTextEditor::Range(0, 50, 0, \
63));  }
 
+}
+
 #include "test_duchain.moc"
--- trunk/playground/devtools/kdevelop4-extra-plugins/php/duchain/tests/test_duchain.h \
#971456:971457 @@ -100,6 +100,7 @@
     void testUnsureReturnType3();
     void testUnsureReturnType4();
     void testDeclareMemberOutOfClass();
+    void testThisRedeclaration();
 };
 
 }


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic