Skip to content

Commit e439891

Browse files
committed
SILGen: Fix edge case where we didn't erase opaque result type in constructor
- Fixes #68298. - Fixes #68277.
1 parent 3166ef3 commit e439891

File tree

3 files changed

+57
-1
lines changed

3 files changed

+57
-1
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1502,7 +1502,7 @@ class SILGenApply : public Lowering::ExprVisitor<SILGenApply> {
15021502
SILType loweredResultTy;
15031503
auto selfMetaTy = selfValue.getType().getAs<AnyMetatypeType>();
15041504
if (selfMetaTy) {
1505-
loweredResultTy = SILType::getPrimitiveObjectType(
1505+
loweredResultTy = SGF.getLoweredLoadableType(
15061506
CanMetatypeType::get(resultTy, selfMetaTy->getRepresentation()));
15071507
} else {
15081508
loweredResultTy = SGF.getLoweredLoadableType(resultTy);
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// RUN: %target-swift-emit-silgen %s
2+
3+
// https://github.com/swiftlang/swift/issues/68277
4+
5+
enum E: P {
6+
static func m() -> some Any { () }
7+
}
8+
9+
protocol P {
10+
associatedtype A
11+
static func m() -> A
12+
}
13+
14+
struct S<T> {
15+
let t: T
16+
}
17+
18+
extension S where T == E.A {
19+
init() {
20+
self.init(t: E.m())
21+
}
22+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// RUN: %target-swift-emit-silgen %s -target %target-cpu-apple-macosx11 -swift-version 5
2+
3+
// REQUIRES: objc_interop
4+
// REQUIRES: OS=macosx
5+
6+
import SwiftUI
7+
8+
protocol StaticFactory {
9+
associatedtype Result
10+
11+
func callAsFunction() -> Self.Result
12+
}
13+
14+
struct ViewFactory: StaticFactory {
15+
let systemName: String
16+
17+
func callAsFunction() -> some View {
18+
Image(systemName: systemName)
19+
.frame(width: 20, height: 20)
20+
}
21+
}
22+
23+
extension Button where Label == ViewFactory.Result {
24+
init(
25+
systemName: String,
26+
action: @escaping () -> Void
27+
) {
28+
self.init(
29+
action: action
30+
) {
31+
ViewFactory(systemName: systemName)()
32+
}
33+
}
34+
}

0 commit comments

Comments
 (0)