diff --git a/lib/Sema/CSGen.cpp b/lib/Sema/CSGen.cpp index 1299db28465ac..e95ce8733cbd8 100644 --- a/lib/Sema/CSGen.cpp +++ b/lib/Sema/CSGen.cpp @@ -1773,8 +1773,6 @@ namespace { } Type visitArrayExpr(ArrayExpr *expr) { - ASTContext &C = CS.getASTContext(); - // An array expression can be of a type T that conforms to the // ArrayLiteralConvertible protocol. auto &tc = CS.getTypeChecker(); @@ -1785,10 +1783,14 @@ namespace { return Type(); } - // FIXME: Protect against broken standard library. - auto elementAssocTy = cast( - arrayProto->lookupDirect( - C.getIdentifier("Element")).front()); + // Assume that ArrayLiteralConvertible contains a single associated type. + AssociatedTypeDecl *elementAssocTy = nullptr; + for (auto decl : arrayProto->getMembers()) { + if ((elementAssocTy = dyn_cast(decl))) + break; + } + if (!elementAssocTy) + return Type(); auto locator = CS.getConstraintLocator(expr); auto contextualType = CS.getContextualType(expr);