Skip to content

Commit 09c15f0

Browse files
author
ematejska
authored
Merge pull request #9417 from slavapestov/superclass-function-conversion-fix-4.0
Sema: Try harder to preserve ParenType sugar when when performing upcasts [4.0]
2 parents 8baf70d + 898ed4b commit 09c15f0

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3266,6 +3266,12 @@ Type TypeChecker::substMemberTypeWithBase(ModuleDecl *module,
32663266
}
32673267

32683268
Type TypeChecker::getSuperClassOf(Type type) {
3269+
if (auto *parenTy = dyn_cast<ParenType>(type.getPointer())) {
3270+
auto superclassTy = getSuperClassOf(parenTy->getUnderlyingType());
3271+
if (!superclassTy)
3272+
return Type();
3273+
return ParenType::get(Context, superclassTy);
3274+
}
32693275
return type->getSuperclass();
32703276
}
32713277

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// RUN: %target-typecheck-verify-swift -swift-version 3
2+
// RUN: %target-typecheck-verify-swift -swift-version 4
3+
4+
// rdar://problem/31969605
5+
6+
class Base {}
7+
class Derived : Base {}
8+
9+
protocol Refined {}
10+
protocol Proto : Refined {}
11+
extension Base : Refined {}
12+
13+
func baseFn(_: Base) {}
14+
15+
func superclassConversion(fn: @escaping (Base) -> ()) {
16+
let _: (Derived) -> () = fn
17+
}
18+
19+
func existentialConversion(fn: @escaping (Refined) -> ()) {
20+
let _: (Proto) -> () = fn
21+
let _: (Base) -> () = fn
22+
let _: (Derived) -> () = fn
23+
}

0 commit comments

Comments
 (0)