Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AST: Targeted fix for conformance lookup issue [3.1] #7887

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion lib/AST/SubstitutionMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "swift/AST/ASTContext.h"
#include "swift/AST/SubstitutionMap.h"
#include "swift/AST/Decl.h"
#include "swift/AST/Module.h"
#include "swift/AST/ProtocolConformance.h"
#include "swift/AST/Types.h"

Expand Down Expand Up @@ -70,7 +71,8 @@ SubstitutionMap::lookupConformance(CanType type,
}

// Check if we have substitutions from one of our parent types.
return forEachParent(type, [&](CanType parent, AssociatedTypeDecl *assocType)
auto result = forEachParent(type,
[&](CanType parent, AssociatedTypeDecl *assocType)
-> Optional<ProtocolConformanceRef> {

auto *parentProto = assocType->getProtocol();
Expand All @@ -87,6 +89,18 @@ SubstitutionMap::lookupConformance(CanType type,

return lookupConformance(proto, sub.getConformances());
});

// FIXME: Narrow fix for broken conformance lookup
if (!result || result->isAbstract()) {
auto substTy = type.subst(*this);
if (!substTy)
return result;

auto *M = proto->getParentModule();
return M->lookupConformance(substTy, proto, nullptr);
}

return result;
}

void SubstitutionMap::
Expand Down
12 changes: 12 additions & 0 deletions validation-test/compiler_crashers_2_fixed/0076-sr3500.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: %target-swift-frontend %s -emit-ir

protocol A {
associatedtype Coordinate: Strideable
func doSomething(_: Range<Coordinate>) -> Coordinate.Stride
}

extension A where Coordinate == Int {
func extensionFunc(_ range: Range<Coordinate>) {
_ = doSomething(range)
}
}