Skip to content

Commit f154b6a

Browse files
authored
Merge pull request #6944 from JaSpa/dont-remove-too-much
Fix the fixit for specialized non-generic types
2 parents 5e16f77 + 5b35f45 commit f154b6a

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -495,8 +495,13 @@ Type TypeChecker::applyGenericArguments(Type type, TypeDecl *decl,
495495

496496
// Don't add fixit on module type; that isn't the right type regardless
497497
// of whether it had generic arguments.
498-
if (!type->is<ModuleType>())
499-
diag.fixItRemove(generic->getAngleBrackets());
498+
if (!type->is<ModuleType>()) {
499+
// When turning a SourceRange into CharSourceRange the closing angle
500+
// brackets on nested generics are lexed as one token.
501+
SourceRange angles = generic->getAngleBrackets();
502+
diag.fixItRemoveChars(angles.Start,
503+
angles.End.getAdvancedLocOrInvalid(1));
504+
}
500505

501506
generic->setInvalid();
502507
return type;

test/Generics/generic_types.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ func useRangeOfPrintables(_ roi : RangeOfPrintables<[Int]>) {
167167

168168
var dfail : Dictionary<Int> // expected-error{{generic type 'Dictionary' specialized with too few type parameters (got 1, but expected 2)}}
169169
var notgeneric : Int<Float> // expected-error{{cannot specialize non-generic type 'Int'}}{{21-28=}}
170+
var notgenericNested : Array<Int<Float>> // expected-error{{cannot specialize non-generic type 'Int'}}{{33-40=}}
170171

171172
// Make sure that redundant typealiases (that map to the same
172173
// underlying type) don't break protocol conformance or use.

0 commit comments

Comments
 (0)