Repository: quarkusio/quarkus
Issue: A @Disposes @Named method doesn't work / is not invoked

### Describe the bug

With this simple configuration

```
    @Singleton
    @Named("myInput")
    public Input input() {
        return new Input();
    }

    public void startInput(
        @Observes StartupEvent evt,
        @Named("myInput") Input input
    ) {
        log.info("Started input...");
    }

    public void stopInput(
        @Disposes @Named("myInput") AutoCloseable input
    ) throws Exception {
        log.info("Stopping input...");
        input.close();
    }
```

The `stopInput` method is never invoked when the app is stopped.

### Expected behavior

The `stopInput` method should be invoked when the app / test is stopped.

### Actual behavior

The `stopInput` method is NOT invoked when the app / test is stopped.

### How to Reproduce?

Run this repo's SimpleTest from IDE
* https://github.com/alesj/quarkus_cl130/tree/named1

You should see this stacktrace

```
Jan 31, 2022 5:21:39 PM io.quarkus.test.junit.QuarkusTestExtension$ExtensionState close
ERROR: Failed to shutdown Quarkus
java.lang.RuntimeException: Unable to stop Quarkus test resource com.alesj.qcl.test.SimpleTestResource@3eee3e2b
	at io.quarkus.test.common.TestResourceManager.close(TestResourceManager.java:152)
	at io.quarkus.test.junit.QuarkusTestExtension$4.close(QuarkusTestExtension.java:290)
	at io.quarkus.test.junit.QuarkusTestExtension$ExtensionState.close(QuarkusTestExtension.java:1189)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.jupiter.engine.execution.ExtensionValuesStore.lambda$closeAllStoredCloseableValues$3(ExtensionValuesStore.java:68)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.accept(ForEachOps.java:183)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.ArrayList.forEach(ArrayList.java:1511)
	at java.base/java.util.stream.SortedOps$RefSortingSink.end(SortedOps.java:395)
	at java.base/java.util.stream.Sink$ChainedReference.end(Sink.java:258)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:510)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ForEachOps$ForEachOp.evaluateSequential(ForEachOps.java:150)
	at java.base/java.util.stream.ForEachOps$ForEachOp$OfRef.evaluateSequential(ForEachOps.java:173)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.forEach(ReferencePipeline.java:596)
	at org.junit.jupiter.engine.execution.ExtensionValuesStore.closeAllStoredCloseableValues(ExtensionValuesStore.java:68)
	at org.junit.jupiter.engine.descriptor.AbstractExtensionContext.close(AbstractExtensionContext.java:77)
	at org.junit.jupiter.engine.execution.JupiterEngineExecutionContext.close(JupiterEngineExecutionContext.java:53)
	at org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor.cleanUp(JupiterEngineDescriptor.java:67)
	at org.junit.jupiter.engine.descriptor.JupiterEngineDescriptor.cleanUp(JupiterEngineDescriptor.java:29)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$cleanUp$10(NodeTestTask.java:167)
	at org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.cleanUp(NodeTestTask.java:167)
	at org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:98)
	at org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
	at org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:107)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
	at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:114)
	at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:86)
	at org.junit.platform.launcher.core.DefaultLauncherSession$DelegatingLauncher.execute(DefaultLauncherSession.java:86)
	at org.junit.platform.launcher.core.SessionPerRequestLauncher.execute(SessionPerRequestLauncher.java:53)
	at com.intellij.junit5.JUnit5IdeaTestRunner.startRunnerWithArgs(JUnit5IdeaTestRunner.java:71)
	at com.intellij.rt.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:33)
	at com.intellij.rt.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:235)
	at com.intellij.rt.junit.JUnitStarter.main(JUnitStarter.java:54)
Caused by: java.lang.IllegalStateException
	at com.alesj.qcl.test.SimpleTestResource.stop(SimpleTestResource.java:22)
	at io.quarkus.test.common.TestResourceManager.close(TestResourceManager.java:150)
```

### Output of `uname -a` or `ver`

_No response_

### Output of `java -version`

_No response_

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

2.6.2.Final

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

_No response_

### Additional information

_No response_

Changed files:
independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java
independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/producer/disposer/DisposerTest.java
independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java

diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java
index 0cabd420434..66f0320e880 100644
--- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java
+++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/BeanDeployment.java
@@ -1029,8 +1029,9 @@ private List<BeanInfo> findBeans(Collection<DotName> beanDefiningAnnotations, Li
         for (MethodInfo producerMethod : producerMethods) {
             BeanInfo declaringBean = beanClassToBean.get(producerMethod.declaringClass());
             if (declaringBean != null) {
-                BeanInfo producerMethodBean = Beans.createProducerMethod(producerMethod, declaringBean, this,
-                        findDisposer(declaringBean, producerMethod, disposers), injectionPointTransformer);
+                Set<Type> beanTypes = Types.getProducerMethodTypeClosure(producerMethod, this);
+                BeanInfo producerMethodBean = Beans.createProducerMethod(beanTypes, producerMethod, declaringBean, this,
+                        findDisposer(beanTypes, declaringBean, producerMethod, disposers), injectionPointTransformer);
                 if (producerMethodBean != null) {
                     beans.add(producerMethodBean);
                     injectionPoints.addAll(producerMethodBean.getAllInjectionPoints());
@@ -1041,8 +1042,9 @@ private List<BeanInfo> findBeans(Collection<DotName> beanDefiningAnnotations, Li
         for (FieldInfo producerField : producerFields) {
             BeanInfo declaringBean = beanClassToBean.get(producerField.declaringClass());
             if (declaringBean != null) {
+                Set<Type> beanTypes = Types.getProducerFieldTypeClosure(producerField, this);
                 BeanInfo producerFieldBean = Beans.createProducerField(producerField, declaringBean, this,
-                        findDisposer(declaringBean, producerField, disposers));
+                        findDisposer(beanTypes, declaringBean, producerField, disposers));
                 if (producerFieldBean != null) {
                     beans.add(producerFieldBean);
                 }
@@ -1102,20 +1104,11 @@ private void registerObserverMethods(Collection<ClassInfo> beanClasses,
         }
     }
 
-    private DisposerInfo findDisposer(BeanInfo declaringBean, AnnotationTarget annotationTarget, List<DisposerInfo> disposers) {
+    private DisposerInfo findDisposer(Set<Type> beanTypes, BeanInfo declaringBean, AnnotationTarget annotationTarget,
+            List<DisposerInfo> disposers) {
         List<DisposerInfo> found = new ArrayList<>();
-        Type beanType;
         Set<AnnotationInstance> qualifiers = new HashSet<>();
-        List<AnnotationInstance> allAnnotations;
-        if (Kind.FIELD.equals(annotationTarget.kind())) {
-            allAnnotations = annotationTarget.asField().annotations();
-            beanType = annotationTarget.asField().type();
-        } else if (Kind.METHOD.equals(annotationTarget.kind())) {
-            allAnnotations = annotationTarget.asMethod().annotations();
-            beanType = annotationTarget.asMethod().returnType();
-        } else {
-            throw new RuntimeException("Unsupported annotation target: " + annotationTarget);
-        }
+        Collection<AnnotationInstance> allAnnotations = getAnnotations(annotationTarget);
         allAnnotations.forEach(a -> extractQualifiers(a).forEach(qualifiers::add));
         for (DisposerInfo disposer : disposers) {
             if (disposer.getDeclaringBean().equals(declaringBean)) {
@@ -1125,8 +1118,14 @@ private DisposerInfo findDisposer(BeanInfo declaringBean, AnnotationTarget annot
                         hasQualifier = false;
                     }
                 }
-                if (hasQualifier && beanResolver.matches(disposer.getDisposedParameterType(), beanType)) {
-                    found.add(disposer);
+                if (hasQualifier) {
+                    Type disposedParamType = disposer.getDisposedParameterType();
+                    for (Type beanType : beanTypes) {
+                        if (beanResolver.matches(disposedParamType, beanType)) {
+                            found.add(disposer);
+                            break;
+                        }
+                    }
                 }
             }
         }
diff --git a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java
index 765b196b2df..fcfe9841063 100644
--- a/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java
+++ b/independent-projects/arc/processor/src/main/java/io/quarkus/arc/processor/Beans.java
@@ -69,11 +69,11 @@ private static ScopeInfo inheritScope(ClassInfo beanClass, BeanDeployment beanDe
         return null;
     }
 
-    static BeanInfo createProducerMethod(MethodInfo producerMethod, BeanInfo declaringBean, BeanDeployment beanDeployment,
+    static BeanInfo createProducerMethod(Set<Type> beanTypes, MethodInfo producerMethod, BeanInfo declaringBean,
+            BeanDeployment beanDeployment,
             DisposerInfo disposer, InjectionPointModifier transformer) {
         Set<AnnotationInstance> qualifiers = new HashSet<>();
         List<ScopeInfo> scopes = new ArrayList<>();
-        Set<Type> types = Types.getProducerMethodTypeClosure(producerMethod, beanDeployment);
         Integer priority = null;
         boolean isAlternative = false;
         boolean isDefaultBean = false;
@@ -169,7 +169,7 @@ static BeanInfo createProducerMethod(MethodInfo producerMethod, BeanInfo declari
         }
 
         List<Injection> injections = Injection.forBean(producerMethod, declaringBean, beanDeployment, transformer);
-        BeanInfo bean = new BeanInfo(producerMethod, beanDeployment, scope, types, qualifiers, injections, declaringBean,
+        BeanInfo bean = new BeanInfo(producerMethod, beanDeployment, scope, beanTypes, qualifiers, injections, declaringBean,
                 disposer, isAlternative, stereotypes, name, isDefaultBean, null, priority);
         for (Injection injection : injections) {
             injection.init(bean);
diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/producer/disposer/DisposerTest.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/producer/disposer/DisposerTest.java
index 705516ecc6b..af2f4e4960d 100644
--- a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/producer/disposer/DisposerTest.java
+++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/producer/disposer/DisposerTest.java
@@ -102,13 +102,13 @@ static class StringProducer {
 
         static final AtomicInteger DESTROYED = new AtomicInteger();
 
-        static final AtomicReference<String> DISPOSED = new AtomicReference<>();
+        static final AtomicReference<CharSequence> DISPOSED = new AtomicReference<>();
 
         @MyQualifier
         @Produces
         String produce = toString();
 
-        void dipose(@Disposes @MyQualifier String value) {
+        void dipose(@Disposes @MyQualifier CharSequence value) {
             DISPOSED.set(value);
         }