Skip to content

Commit f6e5738

Browse files
committed
[SIL] Adjust lowering to account for default expr having type different from parameter
Use `getTypeOfDefaultExpr()` to fetch a type associated with default expression if any. This could only happen in situations where it's acceptable to infer type of generic parameter(s) associated with parameter from default expression.
1 parent eb092c9 commit f6e5738

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lib/SIL/IR/TypeLowering.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2456,8 +2456,16 @@ static CanAnyFunctionType getDefaultArgGeneratorInterfaceType(
24562456
TypeConverter &TC,
24572457
SILDeclRef c) {
24582458
auto *vd = c.getDecl();
2459-
auto resultTy = getParameterAt(vd,
2460-
c.defaultArgIndex)->getInterfaceType();
2459+
auto *pd = getParameterAt(vd, c.defaultArgIndex);
2460+
2461+
Type resultTy;
2462+
2463+
if (auto type = pd->getTypeOfDefaultExpr()) {
2464+
resultTy = type->mapTypeOutOfContext();
2465+
} else {
2466+
resultTy = pd->getInterfaceType();
2467+
}
2468+
24612469
assert(resultTy && "Didn't find default argument?");
24622470

24632471
// The result type might be written in terms of type parameters

0 commit comments

Comments
 (0)