]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for pr113447: from Helen.
authoraclement <aclement>
Thu, 27 Oct 2005 13:49:34 +0000 (13:49 +0000)
committeraclement <aclement>
Thu, 27 Oct 2005 13:49:34 +0000 (13:49 +0000)
tests/bugs150/PR113447.java [new file with mode: 0644]
tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java
tests/src/org/aspectj/systemtest/ajc150/ajc150.xml
weaver/src/org/aspectj/weaver/patterns/ThisOrTargetPointcut.java

diff --git a/tests/bugs150/PR113447.java b/tests/bugs150/PR113447.java
new file mode 100644 (file)
index 0000000..8fd45ed
--- /dev/null
@@ -0,0 +1,40 @@
+public class PR113447 {
+
+       public static void main(String[] args) {
+               PR113447 me = new PR113447();
+               me.method1();
+               me.method3();
+       }
+       
+       public void method1(){}
+
+       public void method3(){}
+}
+
+aspect Super {
+
+       // second method doesn't exist
+       pointcut pc1(PR113447 s) : 
+               (this(s) && execution(void method1()))
+               || (this(s) && execution(void method2()));
+
+       before(PR113447 s) : pc1(s) {
+       }
+       
+       // second method does exist
+       pointcut pc2(PR113447 s) : 
+               (this(s) && execution(void method1()))
+               || (this(s) && execution(void method3()));
+
+       before(PR113447 s) : pc2(s) {
+       }
+       
+       // second method doesn't exist
+       pointcut pc3(PR113447 s) : 
+               (args(s) && execution(void method1()))
+               || (args(s) && execution(void method2()));
+
+       before(PR113447 s) : pc3(s) {
+       }
+
+}
index 282154ca7cec927165d09ca99cd1052bace94af7..fc05dad53662fa5ef0a016a4cac8c45d4fff327b 100644 (file)
@@ -632,6 +632,10 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
          runTest("weaveinfo message for declare at method on an ITDd method");
   }
   
+  public void testNoVerifyErrorWithTwoThisPCDs_pr113447() {
+         runTest("no verify error with two this pcds");
+  }
+  
   // helper methods.....
   
   public SyntheticRepository createRepos(File cpentry) {
index 3796ab1032199223396da8e624da400cfe2e213c..b476f9e39073a27777a3e4b03131297f976f3eb6 100644 (file)
         </compile>
     </ajc-test> 
 
+    <ajc-test dir="bugs150" title="no verify error with two this pcds">
+        <compile files="PR113447.java">
+        </compile>
+        <run class="PR113447"/>
+    </ajc-test> 
+
     <!-- ============================================================================ -->
     <!-- ============================================================================ -->
     
index b458c5d970f9b4987219ba5378456f92ee686a56..da23506eaf9abbe75bc9d572ceb1e8f90b43b328 100644 (file)
@@ -179,17 +179,19 @@ public class ThisOrTargetPointcut extends NameBindingPointcut {
                if (type instanceof BindingTypePattern) {
                  BindingTypePattern btp = (BindingTypePattern)type;
                  // Check if we have already bound something to this formal
-                 if ((state.get(btp.getFormalIndex())!=null) && (lastMatchedShadowId != shadow.shadowId)){
-//                     ISourceLocation pcdSloc = getSourceLocation(); 
-//                     ISourceLocation shadowSloc = shadow.getSourceLocation();
-//                     Message errorMessage = new Message(
-//                             "Cannot use "+(isThis?"this()":"target()")+" to match at this location and bind a formal to type '"+var.getType()+
-//                             "' - the formal is already bound to type '"+state.get(btp.getFormalIndex()).getType()+"'"+
-//                             ".  The secondary source location points to the problematic "+(isThis?"this()":"target()")+".",
-//                             shadowSloc,true,new ISourceLocation[]{pcdSloc}); 
-//                     shadow.getIWorld().getMessageHandler().handleMessage(errorMessage);
+                 Var existingVarInThisSlot = state.get(btp.getFormalIndex());
+                 
+                 if (existingVarInThisSlot != null ) {
+                         
+                       // Is it already bound to exactly the same thing?
+                       if (existingVarInThisSlot.equals(var)) return Literal.TRUE;
+                       
+                       // If state.get() returned non-null then someone has already bound the variable in that slot at
+                       // the shadow 'shadow.shadowId'.  If our 'lastMatchedShadowId' is not the same as 'shadow.shadowId'
+                       // then this pointcut wasn't involved in matching and so shouldn't contribute to binding - so just
+                       // return Literal.TRUE meaning 'no residue'
+                   if (lastMatchedShadowId != shadow.shadowId) return Literal.TRUE;
                        state.setErroneousVar(btp.getFormalIndex());
-                       //return null;
                  }
                }
                return exposeStateForVar(var, type, state, shadow.getIWorld());