Skip to content

Commit fc0c350

Browse files
authored
Merge pull request #82688 from swiftlang/egorzhdan/6.2-void-begin-crash
🍒[cxx-interop] Do not crash for `void begin()`
2 parents c56ec77 + 1a41760 commit fc0c350

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

lib/Sema/CSDiagnostics.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4134,11 +4134,11 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc,
41344134
scratch);
41354135
};
41364136

4137-
auto returnTypeStr = cast<FuncDecl>(found)
4138-
->getResultInterfaceType()
4139-
->getAnyNominal()
4140-
->getName()
4141-
.str();
4137+
auto returnTy =
4138+
cast<FuncDecl>(found)->getResultInterfaceType()->getAnyNominal();
4139+
if (!returnTy)
4140+
continue;
4141+
auto returnTypeStr = returnTy->getName().str();
41424142

41434143
auto methodClangLoc = cxxMethod->getLocation();
41444144
auto methodSwiftLoc =

test/Interop/Cxx/class/invalid-unsafe-projection-errors.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ struct M {
2323
StringLiteral stringLiteral() const { return StringLiteral{"M"}; }
2424
};
2525

26+
struct HasNonIteratorBeginMethod {
27+
void begin() const;
28+
void end() const;
29+
};
30+
2631
//--- test.swift
2732

2833
import Test
@@ -48,3 +53,8 @@ public func test(x: M) {
4853
// CHECK-NOT: error: value of type 'M' has no member 'stringLiteral'
4954
x.stringLiteral()
5055
}
56+
57+
public func test(_ x: HasNonIteratorBeginMethod) {
58+
x.begin()
59+
x.end()
60+
}

0 commit comments

Comments
 (0)