Skip to content

Commit cbb95a2

Browse files
committed
Merge pull request #926 from jtbandes/innermost-params
[AST] Fix inconsistent handling of generic args & params during BoundGenericType::getSubstitutions
2 parents 8b57337 + b97cb48 commit cbb95a2

16 files changed

+21
-20
lines changed

include/swift/AST/Decl.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2827,12 +2827,12 @@ class NominalTypeDecl : public TypeDecl, public DeclContext,
28272827
/// Set the generic signature of this type.
28282828
void setGenericSignature(GenericSignature *sig);
28292829

2830-
/// Retrieve the generic parameter types.
2831-
ArrayRef<GenericTypeParamType *> getGenericParamTypes() const {
2830+
/// Retrieve the innermost generic parameter types.
2831+
ArrayRef<GenericTypeParamType *> getInnermostGenericParamTypes() const {
28322832
if (!GenericSig)
28332833
return { };
28342834

2835-
return GenericSig->getGenericParams();
2835+
return GenericSig->getInnermostGenericParams();
28362836
}
28372837

28382838
/// Retrieve the generic requirements.

lib/AST/Decl.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,9 +1745,9 @@ Type ValueDecl::getInterfaceType() const {
17451745
auto proto = cast<ProtocolDecl>(getDeclContext());
17461746
(void)proto->getType(); // make sure we've computed the type.
17471747
// FIXME: the generic parameter types list should never be empty.
1748-
auto selfTy = proto->getGenericParamTypes().empty()
1748+
auto selfTy = proto->getInnermostGenericParamTypes().empty()
17491749
? proto->getProtocolSelf()->getType()
1750-
: proto->getGenericParamTypes().back();
1750+
: proto->getInnermostGenericParamTypes().back();
17511751
auto &ctx = getASTContext();
17521752
InterfaceTy = DependentMemberType::get(
17531753
selfTy,

lib/IDE/CodeCompletion.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1258,7 +1258,7 @@ ArchetypeTransformer::ArchetypeTransformer(DeclContext *DC, Type Ty) :
12581258
if (!D)
12591259
return;
12601260
SmallVector<Type, 3> Scrach;
1261-
auto Params = D->getGenericParamTypes();
1261+
auto Params = D->getInnermostGenericParamTypes();
12621262
auto Args = BaseTy->getAllGenericArgs(Scrach);
12631263
assert(Params.size() == Args.size());
12641264
for (unsigned I = 0, N = Params.size(); I < N; I ++) {

lib/Sema/CSGen.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2883,7 +2883,8 @@ bool swift::isExtensionApplied(DeclContext &DC, Type BaseTy,
28832883
SmallVector<Type, 3> Scratch;
28842884
auto genericArgs = BaseTy->getAllGenericArgs(Scratch);
28852885
TypeSubstitutionMap substitutions;
2886-
auto genericParams = BaseTy->getNominalOrBoundGenericNominal()->getGenericParamTypes();
2886+
auto genericParams = BaseTy->getNominalOrBoundGenericNominal()
2887+
->getInnermostGenericParamTypes();
28872888
assert(genericParams.size() == genericArgs.size());
28882889
for (unsigned i = 0, n = genericParams.size(); i != n; ++i) {
28892890
auto gp = genericParams[i]->getCanonicalType()->castTo<GenericTypeParamType>();

lib/Sema/ConstraintSystem.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -603,7 +603,7 @@ namespace {
603603

604604
// Open up the generic type.
605605
cs.openGeneric(unboundDecl,
606-
unboundDecl->getGenericParamTypes(),
606+
unboundDecl->getInnermostGenericParamTypes(),
607607
unboundDecl->getGenericRequirements(),
608608
/*skipProtocolSelfConstraint=*/false,
609609
minOpeningDepth,
@@ -612,7 +612,7 @@ namespace {
612612

613613
// Map the generic parameters to their corresponding type variables.
614614
llvm::SmallVector<Type, 4> arguments;
615-
for (auto gp : unboundDecl->getGenericParamTypes()) {
615+
for (auto gp : unboundDecl->getInnermostGenericParamTypes()) {
616616
assert(replacements.count(gp->getCanonicalType()) &&
617617
"Missing generic parameter?");
618618
arguments.push_back(replacements[gp->getCanonicalType()]);

test/Generics/generic_types.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ class Bottom<T : Bottom<Top>> {} // expected-error 2{{type may not reference its
317317
class X6<T> {
318318
let d: D<T>
319319
init(_ value: T) {
320-
d = D(value) // expected-error{{cannot invoke initializer for type 'X6<T>.D<_, _>' with an argument list of type '(T)'}} expected-note{{expected an argument list of type '(T2)'}}
320+
d = D(value)
321321
}
322322
class D<T2> { // expected-error{{generic type 'D' nested in type 'X6' is not allowed}}
323323
init(_ value: T2) {}

validation-test/IDE/crashers/043-swift-boundgenerictype-getsubstitutions.swift

Lines changed: 0 additions & 2 deletions
This file was deleted.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
class A<h{#^A^#class B<a{let:AnyObject.Type=B

validation-test/compiler_crashers/24558-swift-typebase-gatherallsubstitutions.swift renamed to validation-test/compiler_crashers_fixed/24558-swift-typebase-gatherallsubstitutions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

validation-test/compiler_crashers/24624-swift-module-lookupconformance.swift renamed to validation-test/compiler_crashers_fixed/24624-swift-module-lookupconformance.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

validation-test/compiler_crashers/24800-swift-constraints-constraintsystem-matchsuperclasstypes.swift renamed to validation-test/compiler_crashers_fixed/24800-swift-constraints-constraintsystem-matchsuperclasstypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

validation-test/compiler_crashers/27367-swift-boundgenerictype-getsubstitutions.swift renamed to validation-test/compiler_crashers_fixed/27367-swift-boundgenerictype-getsubstitutions.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

validation-test/compiler_crashers/27426-swift-typechecker-validatedecl.swift renamed to validation-test/compiler_crashers_fixed/27426-swift-typechecker-validatedecl.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

validation-test/compiler_crashers/27499-llvm-bitstreamcursor-read.swift renamed to validation-test/compiler_crashers_fixed/27499-llvm-bitstreamcursor-read.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

validation-test/compiler_crashers/27743-swift-constraints-constraintsystem-solvesimplified.swift renamed to validation-test/compiler_crashers_fixed/27743-swift-constraints-constraintsystem-solvesimplified.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

validation-test/compiler_crashers/27800-swift-protocoltype-canonicalizeprotocols.swift renamed to validation-test/compiler_crashers_fixed/27800-swift-protocoltype-canonicalizeprotocols.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not --crash %target-swift-frontend %s -parse
1+
// RUN: not %target-swift-frontend %s -parse
22

33
// Distributed under the terms of the MIT license
44
// Test case submitted to project by https://github.com/practicalswift (practicalswift)

0 commit comments

Comments
 (0)