Skip to content

Commit 8f15815

Browse files
committed
Merge pull request #389 from gregomni/sr-114
Don't add constraints for invalid subscript declarations.
2 parents c99c02b + 8e0b01b commit 8f15815

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/Sema/CSGen.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1517,8 +1517,11 @@ namespace {
15171517

15181518
Type visitSubscriptExpr(SubscriptExpr *expr) {
15191519
ValueDecl *decl = nullptr;
1520-
if (expr->hasDecl())
1520+
if (expr->hasDecl()) {
15211521
decl = expr->getDecl().getDecl();
1522+
if (decl->isInvalid())
1523+
return Type();
1524+
}
15221525
return addSubscriptConstraints(expr, expr->getBase(), expr->getIndex(),
15231526
decl);
15241527
}

test/decl/subscript/subscripting.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,3 +257,18 @@ func testSubscript1(s2 : SubscriptTest2) {
257257
let b = s2[1, "foo"] // expected-error {{cannot subscript a value of type 'SubscriptTest2' with an index of type '(Int, String)'}}
258258
// expected-note @-1 {{expected an argument list of type '(String, String)'}}
259259
}
260+
261+
// sr-114 & rdar://22007370
262+
263+
class Foo {
264+
subscript(key: String) -> String { // expected-note {{'subscript' previously declared here}}
265+
get { a } // expected-error {{use of unresolved identifier 'a'}}
266+
set { b } // expected-error {{use of unresolved identifier 'b'}}
267+
}
268+
269+
subscript(key: String) -> String { // expected-error {{invalid redeclaration of 'subscript'}}
270+
get { a } // expected-error {{use of unresolved identifier 'a'}}
271+
set { b } // expected-error {{use of unresolved identifier 'b'}}
272+
}
273+
}
274+

0 commit comments

Comments
 (0)