Skip to content

Commit 2aaccee

Browse files
committed
Revert "Progress towards nested generic typealiases." apparently broke an LLDB test.
This reverts commit 2896fbb.
1 parent e9ac8c8 commit 2aaccee

File tree

4 files changed

+6
-38
lines changed

4 files changed

+6
-38
lines changed

lib/AST/Type.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,9 +1314,7 @@ TypeBase *NameAliasType::getSinglyDesugaredType() {
13141314

13151315
// The type for a generic TypeAliasDecl is an UnboundGenericType.
13161316
if (TAD->getGenericParams())
1317-
return UnboundGenericType::get(TAD,
1318-
TAD->getDeclContext()->getDeclaredTypeInContext(),
1319-
TAD->getASTContext());
1317+
return UnboundGenericType::get(TAD, Type(), TAD->getASTContext());
13201318

13211319
return getDecl()->getUnderlyingType().getPointer();
13221320
}

lib/Sema/TypeCheckDecl.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3481,7 +3481,8 @@ class DeclChecker : public DeclVisitor<DeclChecker> {
34813481
TAD->getUnderlyingTypeLoc().setInvalidType(TC.Context);
34823482
} else if (TAD->getDeclContext()->isGenericContext()) {
34833483
TAD->setInterfaceType(
3484-
ArchetypeBuilder::mapTypeOutOfContext(TAD, TAD->getType()));
3484+
ArchetypeBuilder::mapTypeOutOfContext(TAD->getDeclContext(),
3485+
TAD->getType()));
34853486
}
34863487

34873488
// We create TypeAliasTypes with invalid underlying types, so we
@@ -6258,9 +6259,6 @@ void TypeChecker::validateDecl(ValueDecl *D, bool resolveTypeParams) {
62586259

62596260
// Check generic parameters, if needed.
62606261
if (auto gp = typeAlias->getGenericParams()) {
6261-
gp->setOuterParameters(
6262-
typeAlias->getDeclContext()->getGenericParamsOfContext());
6263-
62646262
// Validate the generic type parameters.
62656263
if (validateGenericTypeSignature(typeAlias)) {
62666264
markInvalidGenericSignature(typeAlias, *this);
@@ -6274,9 +6272,7 @@ void TypeChecker::validateDecl(ValueDecl *D, bool resolveTypeParams) {
62746272
revertGenericParamList(gp);
62756273

62766274
auto builder = createArchetypeBuilder(typeAlias->getModuleContext());
6277-
auto *parentSig = typeAlias->getDeclContext()->
6278-
getGenericSignatureOfContext();
6279-
checkGenericParamList(&builder, gp, parentSig);
6275+
checkGenericParamList(&builder, gp, nullptr/*parentSig*/);
62806276
finalizeGenericParamList(builder, gp, typeAlias, *this);
62816277
}
62826278
}

lib/Sema/TypeCheckType.cpp

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -455,25 +455,12 @@ Type TypeChecker::applyUnboundGenericArguments(
455455
// If we're completing a generic TypeAlias, then we map the types provided
456456
// onto the underlying type.
457457
if (auto *TAD = dyn_cast<TypeAliasDecl>(unbound->getDecl())) {
458-
auto signature = TAD->getGenericSignature();
459458
assert(TAD->getGenericParams()->getAllArchetypes().size()
460459
== genericArgs.size() &&
461-
signature->getInnermostGenericParams().size() == genericArgs.size()&&
462460
"argument arity mismatch");
463461

464462
SmallVector<Substitution, 4> subs;
465463
subs.reserve(genericArgs.size());
466-
467-
// If we have any nested archetypes from an outer type, include them
468-
// verbatim.
469-
auto outerParams = signature->getGenericParams();
470-
outerParams = outerParams.drop_back(genericArgs.size());
471-
for (auto param : outerParams) {
472-
Type type = resolver->resolveGenericTypeParamType(param);
473-
474-
subs.push_back(Substitution(type, {}));
475-
}
476-
477464
for (auto t : genericArgs)
478465
subs.push_back(Substitution(t.getType(), {}));
479466

test/decl/typealias/typealias.swift

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ let _ : D = D<Int, Int, Float>(a: 1, b: 2)
9292
// expected-error @+1 {{generic parameter 'T3' could not be inferred}}
9393
let _ : D<Int, Int, Float> = D(a: 1, b: 2)
9494

95+
96+
9597
let _ : F = { (a : Int) -> Int in a } // Infer the types of F
9698

9799
// TODO QoI: Cannot infer T1/T2.
@@ -114,21 +116,6 @@ _ = G<Int, String>(a: "foo", b: 42)
114116

115117

116118

117-
// FIXME: Nested generic typealiases aren't working yet.
118-
struct GenericStruct<T> {
119-
typealias TA<U> = MyType<T, U>
120-
121-
func testCapture<S>(s : S, t : T) -> TA<S> { // expected-error {{cannot specialize non-generic type 'MyType<T, U>'}}
122-
return TA<S>(a: t, b : s)
123-
}
124-
}
125-
126-
let _ = GenericStruct<Int>.TA<Float>(a: 4.0, b: 1) // expected-error {{'Int' is not convertible to 'Float'}}
127-
128-
let _ : GenericStruct<Int>.TA<Float> // expected-error {{cannot specialize non-generic type 'MyType<Int, U>'}}
129-
130-
131-
132119
extension A {} // expected-error {{non-nominal type 'A' cannot be extended}}
133120
extension A<T> {} // expected-error {{generic type 'A' specialized with too few type parameters (got 1, but expected 2)}}
134121
extension A<Float,Int> {} // expected-error {{constrained extension must be declared on the unspecialized generic type 'MyType' with constraints specified by a 'where' clause}}

0 commit comments

Comments
 (0)