Skip to content

Commit 8d8c258

Browse files
authored
Merge pull request swiftlang#5625 from rudkx/fix-rdar28387684
Fix crash in member lookup when base type contains type variables.
2 parents 4ee455f + 18c809d commit 8d8c258

File tree

6 files changed

+19
-12
lines changed

6 files changed

+19
-12
lines changed

lib/AST/LookupVisibleDecls.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,8 @@ class OverrideFilteringConsumer : public VisibleDeclConsumer {
718718
// Does it make sense to substitute types?
719719
bool shouldSubst = !BaseTy->hasUnboundGenericType() &&
720720
!isa<AnyMetatypeType>(BaseTy.getPointer()) &&
721-
!BaseTy->isAnyExistentialType();
721+
!BaseTy->isAnyExistentialType() &&
722+
!BaseTy->hasTypeVariable();
722723
ModuleDecl *M = DC->getParentModule();
723724

724725
auto FoundSignature = VD->getOverloadSignature();

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3084,7 +3084,10 @@ bool swift::isExtensionApplied(DeclContext &DC, Type BaseTy,
30843084
ConstraintSystemOptions Options;
30853085
NominalTypeDecl *Nominal = BaseTy->getNominalOrBoundGenericNominal();
30863086
if (!Nominal || !BaseTy->isSpecialized() ||
3087-
ED->getGenericRequirements().empty())
3087+
ED->getGenericRequirements().empty() ||
3088+
// We'll crash if we leak type variables from one constraint
3089+
// system into the new one created below.
3090+
BaseTy->hasTypeVariable())
30883091
return true;
30893092
std::unique_ptr<TypeChecker> CreatedTC;
30903093
// If the current ast context has no type checker, create one for it.
@@ -3101,11 +3104,6 @@ bool swift::isExtensionApplied(DeclContext &DC, Type BaseTy,
31013104
bool Failed = false;
31023105
SmallVector<Type, 3> TypeScratch;
31033106

3104-
// Don't allow type variables from an existing constraint system to
3105-
// leak into the new constraint system created below.
3106-
assert(!BaseTy->hasTypeVariable() &&
3107-
"Unexpected type variable in base type!");
3108-
31093107
// Prepare type substitution map.
31103108
TypeSubstitutionMap Substitutions = BaseTy->getMemberSubstitutions(ED);
31113109
auto resolveType = [&](Type Ty) {

test/Sema/typo_correction.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,11 @@ func test_too_many_but_some_better() {
6969
let match6 = 0
7070
let x = mtch // expected-error {{use of unresolved identifier 'mtch'}}
7171
}
72+
73+
// rdar://problem/28387684
74+
// Don't crash performing typo correction on bound generic types with
75+
// type variables.
76+
_ = [Any]().withUnsafeBufferPointer { (buf) -> [Any] in
77+
guard let base = buf.baseAddress else { return [] }
78+
return (base ..< base + buf.count).m // expected-error {{value of type 'CountableRange<_>' has no member 'm'}}
79+
}

validation-test/IDE/crashers/109-swift-constraints-constraintgraph-change-addedtypevariable.swift

Lines changed: 0 additions & 4 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %target-swift-ide-test -code-completion -code-completion-token=A -source-filename=%s
2+
// REQUIRES: asserts
3+
assert(Range.b
4+
v#^A^#

validation-test/compiler_crashers/28422-swift-genericfunctiontype-get.swift renamed to validation-test/compiler_crashers_fixed/28422-swift-genericfunctiontype-get.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
// See http://swift.org/LICENSE.txt for license information
66
// See http://swift.org/CONTRIBUTORS.txt for the list of Swift project authors
77

8-
// RUN: not --crash %target-swift-frontend %s -parse
8+
// RUN: not %target-swift-frontend %s -parse
99
// REQUIRES: asserts
1010
func d<T{
1111
var d

0 commit comments

Comments
 (0)