@@ -373,20 +373,21 @@ void TypeChecker::checkInheritanceClause(Decl *decl,
373
373
continue ;
374
374
375
375
// Check whether we inherited from the same type twice.
376
- CanType inheritedCanTy = inheritedTy->getCanonicalType ();
377
- auto knownType = inheritedTypes.find (inheritedCanTy);
378
- if (knownType != inheritedTypes.end ()) {
376
+ auto knownPair = inheritedTypes.insert ({ inheritedTy->getCanonicalType (),
377
+ {i, inherited.getSourceRange () }});
378
+ if (knownPair.second == /* insertion failed*/ false ) {
379
+ auto knownIndex = knownPair.first ->second .first ;
380
+ auto knownRange = knownPair.first ->second .second ;
379
381
// If the duplicated type is 'AnyObject', check whether the first was
380
382
// written as 'class'. Downgrade the error to a warning in such cases
381
383
// for backward compatibility with Swift <= 4.
382
384
if (!Context.LangOpts .isSwiftVersionAtLeast (5 ) &&
383
385
inheritedTy->isAnyObject () &&
384
386
(isa<ProtocolDecl>(decl) || isa<AbstractTypeParamDecl>(decl)) &&
385
- Lexer::getTokenAtLocation (Context.SourceMgr ,
386
- knownType->second .second .Start )
387
+ Lexer::getTokenAtLocation (Context.SourceMgr , knownRange.Start )
387
388
.is (tok::kw_class)) {
388
- SourceLoc classLoc = knownType-> second . second .Start ;
389
- SourceRange removeRange = getRemovalRange (knownType-> second . first );
389
+ SourceLoc classLoc = knownRange .Start ;
390
+ SourceRange removeRange = getRemovalRange (knownIndex );
390
391
391
392
diagnose (classLoc, diag::duplicate_anyobject_class_inheritance)
392
393
.fixItRemoveChars (removeRange.Start , removeRange.End );
@@ -398,11 +399,10 @@ void TypeChecker::checkInheritanceClause(Decl *decl,
398
399
diagnose (inherited.getSourceRange ().Start ,
399
400
diag::duplicate_inheritance, inheritedTy)
400
401
.fixItRemoveChars (removeRange.Start , removeRange.End )
401
- .highlight (knownType-> second . second );
402
+ .highlight (knownRange );
402
403
inherited.setInvalidType (Context);
403
404
continue ;
404
405
}
405
- inheritedTypes[inheritedCanTy] = { i, inherited.getSourceRange () };
406
406
407
407
if (inheritedTy->isExistentialType ()) {
408
408
auto layout = inheritedTy->getExistentialLayout ();
0 commit comments