Skip to content

Commit 24988f8

Browse files
committed
[fixits] Don't fixit-remove generic arguments on ModuleType
Seeing Module<Args> is more likely to indicate some catastrophic failure, for instance a missing type with the same name as the module, than that we should remove the generic arguments. rdar://problem/26639477
1 parent 4600b1d commit 24988f8

File tree

4 files changed

+17
-5
lines changed

4 files changed

+17
-5
lines changed

lib/Sema/TypeCheckType.cpp

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -417,9 +417,14 @@ Type TypeChecker::applyGenericArguments(Type type, SourceLoc loc,
417417

418418
auto unbound = type->getAs<UnboundGenericType>();
419419
if (!unbound) {
420-
if (!type->is<ErrorType>())
421-
diagnose(loc, diag::not_a_generic_type, type)
422-
.fixItRemove(generic->getAngleBrackets());
420+
if (!type->is<ErrorType>()) {
421+
auto diag = diagnose(loc, diag::not_a_generic_type, type);
422+
423+
// Don't add fixit on module type; that isn't the right type regardless
424+
// of whether it had generic arguments.
425+
if (!type->is<ModuleType>())
426+
diag.fixItRemove(generic->getAngleBrackets());
427+
}
423428
generic->setInvalid();
424429
return type;
425430
}

test/FixCode/Inputs/module.modulemap

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module Empty {}

test/FixCode/fixits-apply.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %swift -parse -target %target-triple %s -emit-fixits-path %t.remap
1+
// RUN: not %swift -parse -target %target-triple %s -emit-fixits-path %t.remap -I %S/Inputs
22
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
33

44
class Base {}
@@ -156,3 +156,6 @@ func evilCommas(s: String) {
156156
_ = true ? s[s.startIndex..<<#editorplaceholder#>] : ""
157157
_ = [s.startIndex..<<#editorplaceholder#>]
158158
}
159+
160+
import Empty
161+
func testGenericSig(x: Empty<Int>) -> Empty<String> {}

test/FixCode/fixits-apply.swift.result

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: not %swift -parse -target %target-triple %s -emit-fixits-path %t.remap
1+
// RUN: not %swift -parse -target %target-triple %s -emit-fixits-path %t.remap -I %S/Inputs
22
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
33

44
class Base {}
@@ -159,3 +159,6 @@ func evilCommas(s: String) {
159159
_ = true ? s[s.startIndex..<<#editorplaceholder#>] : ""
160160
_ = [s.startIndex..<<#editorplaceholder#>]
161161
}
162+
163+
import Empty
164+
func testGenericSig(x: Empty<Int>) -> Empty<String> {}

0 commit comments

Comments
 (0)