Skip to content

Commit 95cc1f5

Browse files
committed
Sema: Remove the bogus 'reference to invalid associated type' diagnostic
1 parent 5c0226c commit 95cc1f5

File tree

6 files changed

+8
-69
lines changed

6 files changed

+8
-69
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,12 +1147,6 @@ ERROR(ambiguous_module_type,none,
11471147
ERROR(use_nonmatching_operator,none,
11481148
"%0 is not a %select{binary|prefix unary|postfix unary}1 operator",
11491149
(DeclNameRef, unsigned))
1150-
ERROR(unsupported_recursion_in_associated_type_reference,none,
1151-
"unsupported recursion for reference to %kind0 of type %1",
1152-
(const ValueDecl *, Type))
1153-
ERROR(broken_associated_type_witness,none,
1154-
"reference to invalid %kind0 of type %1",
1155-
(const ValueDecl *, Type))
11561150

11571151
ERROR(unspaced_binary_operator_fixit,none,
11581152
"missing whitespace between %0 and %1 operators",

lib/Sema/AssociatedTypeInference.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -597,7 +597,7 @@ static ResolveWitnessResult resolveTypeWitnessViaLookup(
597597
checkTypeWitness(memberTypeInContext, assocType, conformance)) {
598598
nonViable.push_back({typeDecl, checkResult});
599599
} else {
600-
viable.push_back({typeDecl, memberType, nullptr});
600+
viable.push_back({typeDecl, memberType});
601601
}
602602
}
603603

lib/Sema/TypeCheckNameLookup.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ LookupTypeResult TypeChecker::lookupMemberType(DeclContext *dc,
497497
// Add the type to the result set, so that we can diagnose the
498498
// reference instead of just saying the member does not exist.
499499
if (types.insert(memberType->getCanonicalType()).second)
500-
result.addResult({typeDecl, memberType, nullptr});
500+
result.addResult({typeDecl, memberType});
501501

502502
continue;
503503
}
@@ -528,7 +528,7 @@ LookupTypeResult TypeChecker::lookupMemberType(DeclContext *dc,
528528

529529
// If we haven't seen this type result yet, add it to the result set.
530530
if (types.insert(memberType->getCanonicalType()).second)
531-
result.addResult({typeDecl, memberType, nullptr});
531+
result.addResult({typeDecl, memberType});
532532
}
533533

534534
if (!result) {
@@ -566,7 +566,7 @@ LookupTypeResult TypeChecker::lookupMemberType(DeclContext *dc,
566566
auto memberType =
567567
substMemberTypeWithBase(typeDecl, type);
568568
if (types.insert(memberType->getCanonicalType()).second)
569-
result.addResult({typeDecl, memberType, assocType});
569+
result.addResult({typeDecl, memberType});
570570
}
571571
}
572572

lib/Sema/TypeCheckType.cpp

Lines changed: 3 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1351,38 +1351,6 @@ static void diagnoseUnboundGenericType(Type ty, SourceLoc loc) {
13511351
}
13521352
}
13531353

1354-
// Produce a diagnostic if the type we referenced was an
1355-
// associated type but the type itself was erroneous. We'll produce a
1356-
// diagnostic here if the diagnostic for the bad type witness would show up in
1357-
// a different context.
1358-
static void maybeDiagnoseBadConformanceRef(DeclContext *dc,
1359-
Type parentTy,
1360-
SourceLoc loc,
1361-
TypeDecl *typeDecl) {
1362-
auto protocol = dyn_cast<ProtocolDecl>(typeDecl->getDeclContext());
1363-
1364-
// If we weren't given a conformance, go look it up.
1365-
ProtocolConformance *conformance = nullptr;
1366-
if (protocol) {
1367-
auto conformanceRef = lookupConformance(parentTy, protocol);
1368-
if (conformanceRef.isConcrete())
1369-
conformance = conformanceRef.getConcrete();
1370-
}
1371-
1372-
// If any errors have occurred, don't bother diagnosing this cross-file
1373-
// issue.
1374-
ASTContext &ctx = dc->getASTContext();
1375-
if (ctx.Diags.hadAnyError())
1376-
return;
1377-
1378-
auto diagCode =
1379-
(!protocol || (conformance && !conformance->getConditionalRequirementsIfAvailable()))
1380-
? diag::unsupported_recursion_in_associated_type_reference
1381-
: diag::broken_associated_type_witness;
1382-
1383-
ctx.Diags.diagnose(loc, diagCode, typeDecl, parentTy);
1384-
}
1385-
13861354
/// Returns a valid type or ErrorType in case of an error.
13871355
static Type resolveTypeDecl(TypeDecl *typeDecl, DeclContext *foundDC,
13881356
const TypeResolution &resolution,
@@ -1392,16 +1360,6 @@ static Type resolveTypeDecl(TypeDecl *typeDecl, DeclContext *foundDC,
13921360
// depends on the current context and where the type was found.
13931361
Type type = resolution.resolveTypeInContext(typeDecl, foundDC,
13941362
repr->hasGenericArgList());
1395-
1396-
if (type->hasError() && foundDC &&
1397-
(isa<AssociatedTypeDecl>(typeDecl) || isa<TypeAliasDecl>(typeDecl))) {
1398-
auto fromDC = resolution.getDeclContext();
1399-
assert(fromDC && "No declaration context for type resolution?");
1400-
maybeDiagnoseBadConformanceRef(fromDC, foundDC->getDeclaredInterfaceType(),
1401-
repr->getNameLoc().getBaseNameLoc(),
1402-
typeDecl);
1403-
}
1404-
14051363
return applyGenericArguments(type, resolution, silContext, repr);
14061364
}
14071365

@@ -1934,8 +1892,7 @@ static Type resolveQualifiedIdentTypeRepr(const TypeResolution &resolution,
19341892
const auto parentRange = repr->getBase()->getSourceRange();
19351893
auto isExtensionBinding = options.is(TypeResolverContext::ExtensionBinding);
19361894

1937-
auto maybeDiagnoseBadMemberType = [&](TypeDecl *member, Type memberType,
1938-
AssociatedTypeDecl *inferredAssocType) {
1895+
auto maybeDiagnoseBadMemberType = [&](TypeDecl *member, Type memberType) {
19391896
bool hasUnboundOpener = !!resolution.getUnboundTypeOpener();
19401897

19411898
// Type aliases might require adjustment due to @preconcurrency.
@@ -1985,13 +1942,6 @@ static Type resolveQualifiedIdentTypeRepr(const TypeResolution &resolution,
19851942
}
19861943
}
19871944

1988-
// Diagnose a bad conformance reference if we need to.
1989-
if (!options.contains(TypeResolutionFlags::SilenceErrors) &&
1990-
inferredAssocType && memberType->hasError()) {
1991-
maybeDiagnoseBadConformanceRef(DC, parentTy, repr->getLoc(),
1992-
inferredAssocType);
1993-
}
1994-
19951945
// If there are generic arguments, apply them now.
19961946
return applyGenericArguments(memberType, resolution, silContext, repr);
19971947
};
@@ -2021,7 +1971,7 @@ static Type resolveQualifiedIdentTypeRepr(const TypeResolution &resolution,
20211971
if (auto *typeDecl = repr->getBoundDecl()) {
20221972
auto memberType =
20231973
TypeChecker::substMemberTypeWithBase(typeDecl, parentTy);
2024-
return maybeDiagnoseBadMemberType(typeDecl, memberType, nullptr);
1974+
return maybeDiagnoseBadMemberType(typeDecl, memberType);
20251975
}
20261976

20271977
// Phase 1: Find and bind the type declaration.
@@ -2063,7 +2013,6 @@ static Type resolveQualifiedIdentTypeRepr(const TypeResolution &resolution,
20632013
// If we didn't find anything, complain.
20642014
Type memberType;
20652015
TypeDecl *member = nullptr;
2066-
AssociatedTypeDecl *inferredAssocType = nullptr;
20672016
if (!memberTypes) {
20682017
// If we're not allowed to complain or we couldn't fix the
20692018
// source, bail out.
@@ -2078,11 +2027,10 @@ static Type resolveQualifiedIdentTypeRepr(const TypeResolution &resolution,
20782027
} else {
20792028
memberType = memberTypes.back().MemberType;
20802029
member = memberTypes.back().Member;
2081-
inferredAssocType = memberTypes.back().InferredAssociatedType;
20822030
repr->setValue(member, nullptr);
20832031
}
20842032

2085-
return maybeDiagnoseBadMemberType(member, memberType, inferredAssocType);
2033+
return maybeDiagnoseBadMemberType(member, memberType);
20862034
}
20872035

20882036
static bool isDefaultNoEscapeContext(TypeResolutionOptions options) {

lib/Sema/TypeChecker.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,6 @@ enum class DeclTypeCheckingSemantics {
8484
struct LookupTypeResultEntry {
8585
TypeDecl *Member;
8686
Type MemberType;
87-
/// The associated type that the Member/MemberType were inferred for, but only
88-
/// if inference happened when creating this entry.
89-
AssociatedTypeDecl *InferredAssociatedType;
9087
};
9188

9289
/// The result of name lookup for types.

test/multifile/protocol-conformance-broken.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ protocol P {
99
struct X { }
1010

1111
func g() {
12-
let _: X.AT? = nil // expected-error{{reference to invalid associated type 'AT' of type 'X'}}
12+
let _: X.AT? = nil
1313
}
1414

0 commit comments

Comments
 (0)