From 8cea30fedf7a74133c67623ec9286ac9578c9a88 Mon Sep 17 00:00:00 2001 From: aclement Date: Thu, 27 Oct 2005 18:01:54 +0000 Subject: [PATCH] test and fix for pr113861 --- tests/bugs150/pr113861/Test.java | 15 +++++++++++++++ tests/bugs150/pr113861/TestAspect.java | 14 ++++++++++++++ .../aspectj/systemtest/ajc150/Ajc150Tests.java | 6 ++++-- .../src/org/aspectj/systemtest/ajc150/ajc150.xml | 12 +++++++++--- weaver/src/org/aspectj/weaver/Advice.java | 16 ++++++++++------ weaver/src/org/aspectj/weaver/Member.java | 2 ++ weaver/src/org/aspectj/weaver/MemberImpl.java | 2 ++ 7 files changed, 56 insertions(+), 11 deletions(-) create mode 100644 tests/bugs150/pr113861/Test.java create mode 100644 tests/bugs150/pr113861/TestAspect.java diff --git a/tests/bugs150/pr113861/Test.java b/tests/bugs150/pr113861/Test.java new file mode 100644 index 000000000..d9316d09b --- /dev/null +++ b/tests/bugs150/pr113861/Test.java @@ -0,0 +1,15 @@ +package com; +import java.util.*; + +public class Test { + + public static void main(String [] argv) { + new Test().foo(); + } + + Set intsSet = new HashSet(); + + public Set foo() { + return intsSet; + } +} diff --git a/tests/bugs150/pr113861/TestAspect.java b/tests/bugs150/pr113861/TestAspect.java new file mode 100644 index 000000000..76ffa5389 --- /dev/null +++ b/tests/bugs150/pr113861/TestAspect.java @@ -0,0 +1,14 @@ +package com; +import java.util.*; + +public privileged aspect TestAspect { + pointcut gettingMember(Test t) : + target(t) && + get(!public Set com.*.*) && + !within(TestAspect); + + Set around(Test t) : gettingMember(t) { + Set s = proceed(t); + return s; + } +} diff --git a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java index a47dfca3b..87d96f523 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java +++ b/tests/src/org/aspectj/systemtest/ajc150/Ajc150Tests.java @@ -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");} diff --git a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml index e1adcc731..992cd3808 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ajc150.xml @@ -10,7 +10,7 @@ - + @@ -26,7 +26,13 @@ - + + + + + + + @@ -67,7 +73,7 @@ - + diff --git a/weaver/src/org/aspectj/weaver/Advice.java b/weaver/src/org/aspectj/weaver/Advice.java index 704c76088..07d7bc022 100644 --- a/weaver/src/org/aspectj/weaver/Advice.java +++ b/weaver/src/org/aspectj/weaver/Advice.java @@ -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; + } } } } diff --git a/weaver/src/org/aspectj/weaver/Member.java b/weaver/src/org/aspectj/weaver/Member.java index 83e0079b2..76f3e06d3 100644 --- a/weaver/src/org/aspectj/weaver/Member.java +++ b/weaver/src/org/aspectj/weaver/Member.java @@ -60,6 +60,8 @@ public interface Member { public UnresolvedType getDeclaringType(); public UnresolvedType getReturnType(); + + public UnresolvedType getGenericReturnType(); public UnresolvedType getType(); diff --git a/weaver/src/org/aspectj/weaver/MemberImpl.java b/weaver/src/org/aspectj/weaver/MemberImpl.java index 92c1595f5..0c22ff264 100644 --- a/weaver/src/org/aspectj/weaver/MemberImpl.java +++ b/weaver/src/org/aspectj/weaver/MemberImpl.java @@ -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() */ -- 2.39.5