]> source.dussan.org Git - aspectj.git/commitdiff
test and fix for pr113861
authoraclement <aclement>
Thu, 27 Oct 2005 18:01:54 +0000 (18:01 +0000)
committeraclement <aclement>
Thu, 27 Oct 2005 18:01:54 +0000 (18:01 +0000)
tests/bugs150/pr113861/Test.java [new file with mode: 0644]
tests/bugs150/pr113861/TestAspect.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/Advice.java
weaver/src/org/aspectj/weaver/Member.java
weaver/src/org/aspectj/weaver/MemberImpl.java

diff --git a/tests/bugs150/pr113861/Test.java b/tests/bugs150/pr113861/Test.java
new file mode 100644 (file)
index 0000000..d9316d0
--- /dev/null
@@ -0,0 +1,15 @@
+package com;
+import java.util.*;
+
+public class Test {
+
+  public static void main(String [] argv) {
+    new Test().foo();
+  }
+
+  Set<Integer> intsSet = new HashSet<Integer>();
+
+  public Set<Integer> foo() {
+    return intsSet;
+  }
+}
diff --git a/tests/bugs150/pr113861/TestAspect.java b/tests/bugs150/pr113861/TestAspect.java
new file mode 100644 (file)
index 0000000..76ffa53
--- /dev/null
@@ -0,0 +1,14 @@
+package com;
+import java.util.*;
+
+public privileged aspect TestAspect {
+  pointcut gettingMember(Test t) :
+             target(t) &&
+             get(!public Set<Integer> com.*.*) &&
+             !within(TestAspect);
+
+  Set<Integer> around(Test t) : gettingMember(t)  {
+    Set s =  proceed(t);
+    return s;
+  }
+}
index a47dfca3bb538b178ba022b0820a80e43f32c8ba..87d96f523cad00e81fd7c30d4cc6dc8e39ba8eef 100644 (file)
@@ -51,11 +51,12 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testITDCtor_pr112783()       { runTest("Problem with constructor ITDs");}
   */
   
-  public void testUnboundFormal_pr112027()    { runTest("unexpected error unboundFormalInPC");}
-  public void testCCEGenerics_pr113445()      { runTest("Generics ClassCastException");}
+  public void testUnboundFormal_pr112027() { runTest("unexpected error unboundFormalInPC");}
+  public void testCCEGenerics_pr113445()       { runTest("Generics ClassCastException");}
   public void testMatthewsAspect_pr113947_1() { runTest("maws generic aspect - 1");}
   public void testMatthewsAspect_pr113947_2() { runTest("maws generic aspect - 2");}
   
+  
   public void testBadDecp_pr110788_1() { runTest("bad generic decp - 1");}
   public void testBadDecp_pr110788_2() { runTest("bad generic decp - 2");}
   public void testBadDecp_pr110788_3() { runTest("bad generic decp - 3");}
@@ -66,6 +67,7 @@ public class Ajc150Tests extends org.aspectj.testing.XMLBasedAjcTestCase {
   public void testIncompatibleClassChangeError_pr113630_1() {runTest("IncompatibleClassChangeError - errorscenario");}
   public void testIncompatibleClassChangeError_pr113630_2() {runTest("IncompatibleClassChangeError - workingscenario");}
   
+  public void testFieldGetProblemWithGenericField_pr113861() {runTest("field-get problems with generic field");}
 
   public void testDeclareAnnotationOnNonExistentType_pr99191_1() { runTest("declare annotation on non existent type - 1");}
   public void testDeclareAnnotationOnNonExistentType_pr99191_2() { runTest("declare annotation on non existent type - 2");}  
index e1adcc731cccabe34eaa61318221d638a7e1fc6d..992cd38080fd6311ed3c7a53cf7ef91cf368df3b 100644 (file)
@@ -10,7 +10,7 @@
     <ajc-test dir="bugs150" title="Problem with constructor ITDs">
         <compile files="pr112783.aj" options="-1.5"/>
     </ajc-test>
-    
+
     <ajc-test dir="bugs150/pr113947/case1" title="maws generic aspect - 1">
         <compile files="AbstractListSupport.java,AnotherItem.java,Item.java,LinkedList.java,LinkedListItem.java,ListItem.java,StringList.java" options="-1.5">
           <!-- the 'static ref' messages are a bit poor and ought to be eliminated... -->
     <ajc-test dir="bugs150/pr113947/case2" title="maws generic aspect - 2">
         <compile files="AbstractListSupport.java" options="-1.5"/><!--,AnotherItem.java,Item.java,LinkedList.java,LinkedListItem.java,ListItem.java,StringList.java" options="-1.5"/-->
     </ajc-test>
+    
+    <ajc-test dir="bugs150/pr113861" title="field-get problems with generic field">
+        <compile files="Test.java,TestAspect.java" options="-1.5"/>
+        <run class="com.Test"/>
+    </ajc-test>
+    
+    
     <ajc-test dir="bugs150/pr99191" title="declare annotation on non existent type - 1">
         <compile files="pr99191_1.java" options="-1.5">
                <message kind="error" line="4" text="The field 'int C.noSuchField' does not exist"/>
@@ -67,7 +73,7 @@
                <message kind="warning" text="void C.&lt;init&gt;(int) - already has an annotation of type Annotation, cannot add a second instance [Xlint:elementAlreadyAnnotated]"/>
         </compile>
     </ajc-test>
-
     <ajc-test dir="bugs150/pr113630/case1" title="IncompatibleClassChangeError - errorscenario">
         <compile files="Bean.java,BeanTestCase.java,javaBean.java,propertyChanger.java,PropertySupportAspect5.aj" options="-1.5">
           <message kind="warning" line="9" text="Failing match because annotation 'javaBean' on type 'Bean' has SOURCE retention.  Matching allowed when RetentionPolicy is CLASS or RUNTIME"/>
index 704c760880c348a50b0339de8fcc4141a0d31b0a..07d7bc022b9e0930cd18c0fdbb28de041e973b57 100644 (file)
@@ -158,12 +158,16 @@ public abstract class Advice extends ShadowMunger {
                                        }
                                } else if (getSignature().getReturnType().equals(UnresolvedType.OBJECT)) {
                                        return true;
-                               } else if(!shadow.getReturnType().resolve(world).isAssignableFrom(getSignature().getReturnType().resolve(world))) {
-                                       //System.err.println(this + ", " + sourceContext + ", " + start);
-                                               world.showMessage(IMessage.ERROR,
-                                                               WeaverMessages.format(WeaverMessages.INCOMPATIBLE_RETURN_TYPE,shadow),
-                                                               getSourceLocation(), shadow.getSourceLocation());
-                                       return false;
+                               } else {
+                                       ResolvedType shadowReturnType = shadow.getReturnType().resolve(world);
+                                       ResolvedType adviceReturnType = getSignature().getGenericReturnType().resolve(world);
+                                       if(!shadowReturnType.isAssignableFrom(adviceReturnType)) {
+                                               //System.err.println(this + ", " + sourceContext + ", " + start);
+                                                       world.showMessage(IMessage.ERROR,
+                                                                       WeaverMessages.format(WeaverMessages.INCOMPATIBLE_RETURN_TYPE,shadow),
+                                                                       getSourceLocation(), shadow.getSourceLocation());
+                                               return false;
+                                       }
                                }
                        }
                }
index 83e0079b2eadc457e790060eb7f1468705310118..76f3e06d3f067fd82924826b45454669f0c6a0e6 100644 (file)
@@ -60,6 +60,8 @@ public interface Member {
        public UnresolvedType getDeclaringType();
 
        public UnresolvedType getReturnType();
+       
+       public UnresolvedType getGenericReturnType();
 
        public UnresolvedType getType();
 
index 92c1595f58be1a5af7f5a310e69f5551cf72d789..0c22ff2647a74915bb8610c28ffbced209443515 100644 (file)
@@ -457,6 +457,8 @@ public class MemberImpl implements Comparable, AnnotatedElement,Member {
         * @see org.aspectj.weaver.Member#getReturnType()
         */
     public UnresolvedType getReturnType() { return returnType; }
+    
+    public UnresolvedType getGenericReturnType() { return getReturnType(); }
     /* (non-Javadoc)
         * @see org.aspectj.weaver.Member#getType()
         */