Skip to content

Commit f19ef79

Browse files
committed
Sema: Fix crash when substitution into generic typealias fails
Fixes <rdar://problem/29060933>.
1 parent cc9dd47 commit f19ef79

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -562,7 +562,7 @@ Type TypeChecker::applyUnboundGenericArguments(
562562
type = ArchetypeBuilder::mapTypeOutOfContext(TAD, TAD->getUnderlyingType());
563563
}
564564

565-
type = type.subst(dc->getParentModule(), subs, None);
565+
type = type.subst(dc->getParentModule(), subs, SubstFlags::UseErrorType);
566566

567567
// FIXME: return a SubstitutedType to preserve the fact that
568568
// we resolved a generic TypeAlias, for availability diagnostics.

test/decl/typealias/generic.swift

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,9 @@ func takesSugaredType2(m: GenericClass<Int>.TA<Float>) {
224224
}
225225

226226

227+
//
228+
// Error paths
229+
//
227230

228231
extension A {} // expected-error {{non-nominal type 'A' cannot be extended}}
229232
extension A<T> {} // expected-error {{generic type 'A' specialized with too few type parameters (got 1, but expected 2)}}
@@ -232,6 +235,26 @@ extension C<T> {} // expected-error {{use of undeclared type 'T'}}
232235
extension C<Int> {} // expected-error {{constrained extension must be declared on the unspecialized generic type 'MyType' with constraints specified by a 'where' clause}}
233236

234237

238+
protocol ErrorQ {
239+
associatedtype Y
240+
}
241+
protocol ErrorP {
242+
associatedtype X: ErrorQ // expected-note {{protocol requires nested type 'X'; do you want to add it?}}
243+
}
244+
245+
typealias ErrorA<T: ErrorP> = T.X.Y
246+
247+
struct ErrorB : ErrorP { // expected-error {{type 'ErrorB' does not conform to protocol 'ErrorP'}}
248+
typealias X = ErrorC // expected-note {{possibly intended match 'ErrorB.X' (aka 'ErrorC') does not conform to 'ErrorQ'}}
249+
}
250+
251+
struct ErrorC {
252+
typealias Y = Int
253+
}
254+
255+
typealias Y = ErrorA<ErrorB>
256+
257+
235258
//
236259
// Generic typealiases in protocols
237260
//

0 commit comments

Comments
 (0)