Repository: quarkusio/quarkus
Issue: Generic Syntetic Bean cause ambigious type resolution when none exists

### Describe the bug

When a Synthetic bean for a generic type is created like this:
```
    SyntheticBeanBuildItem addMyGenericInterface() {
        DotName interfaceName = DotName.createSimple(MyGenericInterface.class.getName());
        DotName numberTypeName = DotName.createSimple(AtomicInteger.class.getName());
        DotName stringTypeName = DotName.createSimple(String.class.getName());
        return SyntheticBeanBuildItem.configure(interfaceName)
                .creator(methodCreator -> {
                    FunctionCreator functionCreator = methodCreator.createFunction(MyGenericInterface.class);
                    BytecodeCreator functionBytecode = functionCreator.getBytecode();
                    functionBytecode.returnValue(functionBytecode.loadNull());
                    methodCreator.returnValue(functionCreator.getInstance());
                })
                .types(ParameterizedType.create(interfaceName,
                                                new Type[]{
                                                        Type.create(numberTypeName, Type.Kind.CLASS),
                                                        Type.create(stringTypeName, Type.Kind.CLASS)
                                                }, null))
                .done();
    }
```
an "ambigious type resolution" occurs within ArC, with the same synthetic bean showing up twice.

Thus, it is impossible to inject generic Syntetic beans, since with the types argument, it cause ambiguity, and without it, it cannot find an instance.

### Expected behavior

```
@Inject
MyGenericInterface<AtomicInteger, String> myGenericInterface;
```

causes `myGenericInterface` to be injected with the synthetic bean

### Actual behavior

```
java.lang.RuntimeException: 
java.lang.RuntimeException: io.quarkus.builder.BuildException: Build failure: Build failed due to errors
	[error]: Build step io.quarkus.arc.deployment.ArcProcessor#validate threw an exception: javax.enterprise.inject.spi.DeploymentException: javax.enterprise.inject.AmbiguousResolutionException: Ambiguous dependencies for type org.acme.my.ext.MyGenericInterface<java.util.concurrent.atomic.AtomicInteger, java.lang.String> and qualifiers [@Default]
	- java member: org.acme.my.ext.test.MyExtTest#myGenericInterface
	- declared on CLASS bean [types=[org.acme.my.ext.test.MyExtTest, java.lang.Object], qualifiers=[@Default, @Any], target=org.acme.my.ext.test.MyExtTest]
	- available beans:
		- SYNTHETIC bean [types=[org.acme.my.ext.MyGenericInterface, org.acme.my.ext.MyGenericInterface<java.util.concurrent.atomic.AtomicInteger, java.lang.String>], qualifiers=[@Default, @Any], target=n/a]
		- SYNTHETIC bean [types=[org.acme.my.ext.MyGenericInterface, org.acme.my.ext.MyGenericInterface<java.util.concurrent.atomic.AtomicInteger, java.lang.String>], qualifiers=[@Default, @Any], target=n/a]
	at io.quarkus.arc.processor.BeanDeployment.processErrors(BeanDeployment.java:1190)
	at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:268)
	at io.quarkus.arc.processor.BeanProcessor.initialize(BeanProcessor.java:129)
	at io.quarkus.arc.deployment.ArcProcessor.validate(ArcProcessor.java:418)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.base/java.lang.reflect.Method.invoke(Method.java:566)
	at io.quarkus.deployment.ExtensionLoader$2.execute(ExtensionLoader.java:820)
	at io.quarkus.builder.BuildContext.run(BuildContext.java:277)
	at org.jboss.threads.ContextHandler$1.runWith(ContextHandler.java:18)
	at org.jboss.threads.EnhancedQueueExecutor$Task.run(EnhancedQueueExecutor.java:2449)
	at org.jboss.threads.EnhancedQueueExecutor$ThreadBody.run(EnhancedQueueExecutor.java:1478)
	at java.base/java.lang.Thread.run(Thread.java:829)
	at org.jboss.threads.JBossThread.run(JBossThread.java:501)
Caused by: javax.enterprise.inject.AmbiguousResolutionException: Ambiguous dependencies for type org.acme.my.ext.MyGenericInterface<java.util.concurrent.atomic.AtomicInteger, java.lang.String> and qualifiers [@Default]
	- java member: org.acme.my.ext.test.MyExtTest#myGenericInterface
	- declared on CLASS bean [types=[org.acme.my.ext.test.MyExtTest, java.lang.Object], qualifiers=[@Default, @Any], target=org.acme.my.ext.test.MyExtTest]
	- available beans:
		- SYNTHETIC bean [types=[org.acme.my.ext.MyGenericInterface, org.acme.my.ext.MyGenericInterface<java.util.concurrent.atomic.AtomicInteger, java.lang.String>], qualifiers=[@Default, @Any], target=n/a]
		- SYNTHETIC bean [types=[org.acme.my.ext.MyGenericInterface, org.acme.my.ext.MyGenericInterface<java.util.concurrent.atomic.AtomicInteger, java.lang.String>], qualifiers=[@Default, @Any], target=n/a]
	at io.quarkus.arc.processor.Beans.resolveInjectionPoint(Beans.java:576)
	at io.quarkus.arc.processor.BeanInfo.init(BeanInfo.java:470)
	at io.quarkus.arc.processor.BeanDeployment.init(BeanDeployment.java:256)
	... 13 more

```

### How to Reproduce?

Reproducer: https://github.com/Christopher-Chianelli/issue-reproducer/tree/quarkus-extension-syntetic-bean

Steps to reproduce:

1. cd `my-ext`
2. `mvn clean install`
3. Notice `MyExtTest` writeYourOwnUnitTest fails because myGenericInterface cannot be injected because ambiguous resolution (despite  `addMyGenericInterface` only returing 1 instance of it)

### Output of `uname -a` or `ver`

Linux 5.14.9-200.fc34.x86_64

### Output of `java -version`

openjdk 11.0.12 2021-07-20

### GraalVM version (if different from Java)

_No response_

### Quarkus version or git rev

fffe31b91b05774bbaa4456f0a57d40132b2fd2a

### Build tool (ie. output of `mvnw --version` or `gradlew --version`)

Apache Maven 3.6.3 (cecedd343002696d0abb50b32b541b8a6ba2883f)

### 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/buildextension/beans/BeanRegistrarTest.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 1deca533a82..4f9ccde761d 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
@@ -291,28 +291,28 @@ void init(Consumer<BytecodeTransformer> bytecodeTransformerConsumer,
     private void initBeanByTypeMap() {
         Map<DotName, List<BeanInfo>> map = new HashMap<>();
         for (BeanInfo bean : beans) {
-            for (Type beanType : bean.types) {
-                if (DotNames.OBJECT.equals(beanType.name())) {
+            bean.types.stream().map(Type::name).distinct().forEach(rawTypeName -> {
+                if (DotNames.OBJECT.equals(rawTypeName)) {
                     // Every bean has java.lang.Object - no need to cache results here
-                    continue;
+                    return;
                 }
-                List<BeanInfo> beans = map.get(beanType.name());
+                List<BeanInfo> beans = map.get(rawTypeName);
                 if (beans == null) {
                     // Very often, there will be exactly one bean for a given type
-                    map.put(beanType.name(), List.of(bean));
+                    map.put(rawTypeName, List.of(bean));
                 } else {
                     if (beans.size() == 1) {
-                        map.put(beanType.name(), List.of(beans.get(0), bean));
+                        map.put(rawTypeName, List.of(beans.get(0), bean));
                     } else {
                         BeanInfo[] array = new BeanInfo[beans.size() + 1];
                         for (int i = 0; i < beans.size(); i++) {
                             array[i] = beans.get(i);
                         }
                         array[beans.size()] = bean;
-                        map.put(beanType.name(), List.of(array));
+                        map.put(rawTypeName, List.of(array));
                     }
                 }
-            }
+            });
         }
         this.beansByType = map;
     }
diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/beans/BeanRegistrarTest.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/beans/BeanRegistrarTest.java
index dec25178504..06a86fe616e 100644
--- a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/beans/BeanRegistrarTest.java
+++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/beans/BeanRegistrarTest.java
@@ -20,15 +20,19 @@
 import java.lang.annotation.Inherited;
 import java.lang.annotation.Retention;
 import java.lang.annotation.Target;
+import java.util.List;
 import java.util.Map;
 import java.util.Optional;
 import javax.enterprise.context.ApplicationScoped;
 import javax.enterprise.context.spi.CreationalContext;
 import javax.enterprise.util.AnnotationLiteral;
+import javax.inject.Inject;
 import javax.inject.Qualifier;
 import javax.inject.Singleton;
 import org.jboss.jandex.DotName;
+import org.jboss.jandex.ParameterizedType;
 import org.jboss.jandex.Type;
+import org.jboss.jandex.Type.Kind;
 import org.junit.jupiter.api.AfterAll;
 import org.junit.jupiter.api.Assertions;
 import org.junit.jupiter.api.Test;
@@ -40,8 +44,9 @@ public class BeanRegistrarTest {
 
     @RegisterExtension
     public ArcTestContainer container = ArcTestContainer.builder()
-            .beanClasses(UselessBean.class, MyQualifier.class, NextQualifier.class)
+            .beanClasses(UselessBean.class, MyQualifier.class, NextQualifier.class, ListConsumer.class)
             .removeUnusedBeans(true)
+            .addRemovalExclusion(b -> b.hasType(DotName.createSimple(ListConsumer.class.getName())))
             .beanRegistrars(new TestRegistrar()).build();
 
     @AfterAll
@@ -74,6 +79,18 @@ public void testSyntheticBean() {
         assertEquals(Integer.valueOf(152), Arc.container().instance(Integer.class).get());
         assertEquals("Hello Frantisek!", Arc.container().instance(String.class).get());
         assertEquals("Hello Roman!", Arc.container().instance(String.class, new NextQualifierLiteral()).get());
+        @SuppressWarnings({ "resource" })
+        List<String> list = Arc.container().instance(ListConsumer.class).get().list;
+        assertEquals(1, list.size());
+        assertEquals("foo", list.get(0));
+    }
+
+    @Singleton
+    static class ListConsumer {
+
+        @Inject
+        List<String> list;
+
     }
 
     static class TestRegistrar implements BeanRegistrar {
@@ -102,13 +119,28 @@ public void register(RegistrationContext context) {
             integerConfigurator.scope(Singleton.class);
             integerConfigurator.done();
 
-            context.configure(String.class).unremovable().types(String.class).param("name", "Frantisek")
-                    .creator(StringCreator.class).done();
+            context.configure(String.class)
+                    .unremovable()
+                    .types(String.class)
+                    .param("name", "Frantisek")
+                    .creator(StringCreator.class)
+                    .done();
 
             context.configure(String.class).types(String.class).param("name", "Roman")
-                    .creator(StringCreator.class).addQualifier().annotation(NextQualifier.class).addValue("name", "Roman")
-                    .addValue("age", 42)
-                    .addValue("classes", new Class[] { String.class }).done().unremovable().done();
+                    .creator(StringCreator.class)
+                    .addQualifier().annotation(NextQualifier.class).addValue("name", "Roman").addValue("age", 42)
+                    .addValue("classes", new Class[] { String.class }).done()
+                    .unremovable()
+                    .done();
+
+            context.configure(List.class)
+                    // List, List<String>
+                    .addType(Type.create(DotName.createSimple(List.class.getName()), Kind.CLASS))
+                    .addType(ParameterizedType.create(DotName.createSimple(List.class.getName()),
+                            new Type[] { Type.create(DotName.createSimple(String.class.getName()), Kind.CLASS) }, null))
+                    .creator(ListCreator.class)
+                    .unremovable()
+                    .done();
 
             uselessBean = context.beans()
                     .assignableTo(
@@ -129,6 +161,15 @@ public String create(CreationalContext<String> creationalContext, Map<String, Ob
 
     }
 
+    public static class ListCreator implements BeanCreator<List<String>> {
+
+        @Override
+        public List<String> create(CreationalContext<List<String>> creationalContext, Map<String, Object> params) {
+            return List.of("foo");
+        }
+
+    }
+
     public static class SimpleDestroyer implements BeanDestroyer<Integer> {
 
         @Override