diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index f82fe9f0d8c13..74b6082bf5e1e 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -4134,11 +4134,11 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc, scratch); }; - auto returnTypeStr = cast(found) - ->getResultInterfaceType() - ->getAnyNominal() - ->getName() - .str(); + auto returnTy = + cast(found)->getResultInterfaceType()->getAnyNominal(); + if (!returnTy) + continue; + auto returnTypeStr = returnTy->getName().str(); auto methodClangLoc = cxxMethod->getLocation(); auto methodSwiftLoc = diff --git a/test/Interop/Cxx/class/invalid-unsafe-projection-errors.swift b/test/Interop/Cxx/class/invalid-unsafe-projection-errors.swift index 6893d36794d14..8b5d82871c7cb 100644 --- a/test/Interop/Cxx/class/invalid-unsafe-projection-errors.swift +++ b/test/Interop/Cxx/class/invalid-unsafe-projection-errors.swift @@ -23,6 +23,11 @@ struct M { StringLiteral stringLiteral() const { return StringLiteral{"M"}; } }; +struct HasNonIteratorBeginMethod { + void begin() const; + void end() const; +}; + //--- test.swift import Test @@ -48,3 +53,8 @@ public func test(x: M) { // CHECK-NOT: error: value of type 'M' has no member 'stringLiteral' x.stringLiteral() } + +public func test(_ x: HasNonIteratorBeginMethod) { + x.begin() + x.end() +}