Skip to content

Commit b632534

Browse files
author
Gabor Horvath
committed
[cxx-interop] Interpret Self as a static shorthand for FRTs
We do not have dynamic self metadata for foreign reference types. rdar://145066864
1 parent c28279f commit b632534

File tree

3 files changed

+19
-1
lines changed

3 files changed

+19
-1
lines changed

lib/Sema/PreCheckTarget.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -709,7 +709,8 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
709709
if (DeclContext *typeContext = DC->getInnermostTypeContext()){
710710
Type SelfType = typeContext->getSelfInterfaceType();
711711

712-
if (typeContext->getSelfClassDecl())
712+
if (typeContext->getSelfClassDecl() &&
713+
!typeContext->getSelfClassDecl()->isForeignReferenceType())
713714
SelfType = DynamicSelfType::get(SelfType, Context);
714715
return new (Context)
715716
TypeExpr(new (Context) SelfTypeRepr(SelfType, Loc));

lib/Sema/TypeCheckType.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1679,6 +1679,11 @@ static SelfTypeKind getSelfTypeKind(DeclContext *dc,
16791679
if (!typeDC->getSelfClassDecl())
16801680
return SelfTypeKind::StaticSelf;
16811681

1682+
// For foreign reference types `Self` is a shorthand for the nominal type.
1683+
if (typeDC->getSelfClassDecl() &&
1684+
typeDC->getSelfClassDecl()->isForeignReferenceType())
1685+
return SelfTypeKind::StaticSelf;
1686+
16821687
// In class methods, 'Self' is the DynamicSelfType and can only appear in
16831688
// the return type.
16841689
switch (options.getBaseContext()) {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// RUN: %target-run-simple-swift(-I %S/Inputs/ -Xfrontend -enable-experimental-cxx-interop -Xfrontend -disable-availability-checking -Onone)
2+
// REQUIRES: executable_test
3+
4+
import ReferenceCounted
5+
6+
extension NS.LocalCount {
7+
static func g() {}
8+
9+
public func f() {
10+
Self.g()
11+
}
12+
}

0 commit comments

Comments
 (0)