@@ -2105,11 +2105,22 @@ directReferencesForUnqualifiedTypeLookup(DeclNameRef name,
2105
2105
auto descriptor = UnqualifiedLookupDescriptor (name, dc, loc, options);
2106
2106
auto lookup = evaluateOrDefault (ctx.evaluator ,
2107
2107
UnqualifiedLookupRequest{descriptor}, {});
2108
+
2109
+ unsigned nominalTypeDeclCount = 0 ;
2108
2110
for (const auto &result : lookup.allResults ()) {
2109
2111
auto typeDecl = cast<TypeDecl>(result.getValueDecl ());
2112
+
2113
+ if (isa<NominalTypeDecl>(typeDecl))
2114
+ nominalTypeDeclCount++;
2115
+
2110
2116
results.push_back (typeDecl);
2111
2117
}
2112
2118
2119
+ // If we saw multiple nominal type declarations with the same name,
2120
+ // the result of the lookup is definitely ambiguous.
2121
+ if (nominalTypeDeclCount > 1 )
2122
+ results.clear ();
2123
+
2113
2124
return results;
2114
2125
}
2115
2126
@@ -2607,54 +2618,6 @@ CustomAttrNominalRequest::evaluate(Evaluator &evaluator,
2607
2618
}
2608
2619
}
2609
2620
2610
- // If we have more than one attribute declaration, we have an ambiguity.
2611
- // So, emit an ambiguity diagnostic.
2612
- if (auto typeRepr = attr->getTypeRepr ()) {
2613
- if (nominals.size () > 1 ) {
2614
- SmallVector<NominalTypeDecl *, 4 > ambiguousCandidates;
2615
- // Filter out declarations that cannot be attributes.
2616
- for (auto decl : nominals) {
2617
- if (isa<ProtocolDecl>(decl)) {
2618
- continue ;
2619
- }
2620
- ambiguousCandidates.push_back (decl);
2621
- }
2622
- if (ambiguousCandidates.size () > 1 ) {
2623
- auto attrName = nominals.front ()->getName ();
2624
- ctx.Diags .diagnose (typeRepr->getLoc (),
2625
- diag::ambiguous_custom_attribute_ref, attrName);
2626
- for (auto candidate : ambiguousCandidates) {
2627
- ctx.Diags .diagnose (candidate->getLoc (),
2628
- diag::found_attribute_candidate);
2629
- // If the candidate is a top-level attribute, let's suggest
2630
- // adding module name to resolve the ambiguity.
2631
- if (candidate->getDeclContext ()->isModuleScopeContext ()) {
2632
- auto moduleName = candidate->getParentModule ()->getName ();
2633
- ctx.Diags
2634
- .diagnose (typeRepr->getLoc (),
2635
- diag::ambiguous_custom_attribute_ref_fix,
2636
- moduleName.str (), attrName, moduleName)
2637
- .fixItInsert (typeRepr->getLoc (), moduleName.str ().str () + " ." );
2638
- }
2639
- }
2640
- return nullptr ;
2641
- }
2642
- }
2643
- }
2644
-
2645
- // There is no nominal type with this name, so complain about this being
2646
- // an unknown attribute.
2647
- std::string typeName;
2648
- if (auto typeRepr = attr->getTypeRepr ()) {
2649
- llvm::raw_string_ostream out (typeName);
2650
- typeRepr->print (out);
2651
- } else {
2652
- typeName = attr->getType ().getString ();
2653
- }
2654
-
2655
- ctx.Diags .diagnose (attr->getLocation (), diag::unknown_attribute, typeName);
2656
- attr->setInvalid ();
2657
-
2658
2621
return nullptr ;
2659
2622
}
2660
2623
0 commit comments