Skip to content

Sema: Fix crash when substitution into generic typealias fails #5616

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Sema/TypeCheckType.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -562,7 +562,7 @@ Type TypeChecker::applyUnboundGenericArguments(
type = ArchetypeBuilder::mapTypeOutOfContext(TAD, TAD->getUnderlyingType());
}

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

// FIXME: return a SubstitutedType to preserve the fact that
// we resolved a generic TypeAlias, for availability diagnostics.
Expand Down
23 changes: 23 additions & 0 deletions test/decl/typealias/generic.swift
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,9 @@ func takesSugaredType2(m: GenericClass<Int>.TA<Float>) {
}


//
// Error paths
//

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


protocol ErrorQ {
associatedtype Y
}
protocol ErrorP {
associatedtype X: ErrorQ // expected-note {{protocol requires nested type 'X'; do you want to add it?}}
}

typealias ErrorA<T: ErrorP> = T.X.Y

struct ErrorB : ErrorP { // expected-error {{type 'ErrorB' does not conform to protocol 'ErrorP'}}
typealias X = ErrorC // expected-note {{possibly intended match 'ErrorB.X' (aka 'ErrorC') does not conform to 'ErrorQ'}}
}

struct ErrorC {
typealias Y = Int
}

typealias Y = ErrorA<ErrorB>


//
// Generic typealiases in protocols
//
Expand Down