Skip to content

Commit 4daf56b

Browse files
committed
SILGen: Fix calls to literal constructors defined in protocol extensions
Fixes <https://bugs.swift.org/browse/SR-3173>.
1 parent 54754c5 commit 4daf56b

File tree

2 files changed

+35
-3
lines changed

2 files changed

+35
-3
lines changed

lib/SILGen/SILGenApply.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4694,15 +4694,16 @@ static RValue emitApplyAllocatingInitializer(SILGenFunction &SGF,
46944694
{
46954695
// Determine the self metatype type.
46964696
CanSILFunctionType substFnType =
4697-
SGF.getLoweredType(substFormalType, /*uncurryLevel=*/1)
4698-
.castTo<SILFunctionType>();
4697+
initConstant.SILFnType->substGenericArgs(SGF.SGM.M, subs);
46994698
SILType selfParamMetaTy = substFnType->getSelfParameter().getSILType();
47004699

47014700
if (overriddenSelfType) {
47024701
// If the 'self' type has been overridden, form a metatype to the
47034702
// overriding 'Self' type.
47044703
Type overriddenSelfMetaType =
4705-
MetatypeType::get(overriddenSelfType, SGF.getASTContext());
4704+
MetatypeType::get(overriddenSelfType,
4705+
selfParamMetaTy.castTo<MetatypeType>()
4706+
->getRepresentation());
47064707
selfMetaTy =
47074708
SGF.getLoweredType(overriddenSelfMetaType->getCanonicalType());
47084709
} else {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// RUN: %target-swift-frontend %s -emit-silgen
2+
3+
protocol P: Equatable, ExpressibleByStringLiteral {
4+
var uid: String { get }
5+
init(uid: String)
6+
}
7+
8+
extension P {
9+
// Equatable
10+
public static func ==(lhs: Self, rhs: Self) -> Bool {
11+
return lhs.uid == rhs.uid
12+
}
13+
14+
// ExpressibleByStringLiteral
15+
public init(stringLiteral value: String) {
16+
self.init(uid: value)
17+
}
18+
public init(unicodeScalarLiteral value: String) {
19+
self.init(uid: value)
20+
}
21+
public init(extendedGraphemeClusterLiteral value: String) {
22+
self.init(uid: value)
23+
}
24+
}
25+
26+
struct Test: P {
27+
var uid: String
28+
static let s1: Test = "s1"
29+
}
30+
31+
Test.s1 == "test"

0 commit comments

Comments
 (0)