Skip to content

Commit 8e0b01b

Browse files
committed
Don't add constraints for invalid subscript declarations.
This fixes the crash in sr-114. Adding constraints for the invalid operator decl means constraining to the error type, which fails an assertion later on while binding an overload choice. In all the normal function/method overload choice cases, if the decl is invalid that choice gets skipped (never generated), so this is just another case of the existing way of doing things
1 parent 447c986 commit 8e0b01b

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
@@ -259,3 +259,18 @@ func testSubscript1(s2 : SubscriptTest2) {
259259
let b = s2[1, "foo"] // expected-error {{cannot subscript a value of type 'SubscriptTest2' with an index of type '(Int, String)'}}
260260
// expected-note @-1 {{expected an argument list of type '(String, String)'}}
261261
}
262+
263+
// sr-114 & rdar://22007370
264+
265+
class Foo {
266+
subscript(key: String) -> String { // expected-note {{'subscript' previously declared here}}
267+
get { a } // expected-error {{use of unresolved identifier 'a'}}
268+
set { b } // expected-error {{use of unresolved identifier 'b'}}
269+
}
270+
271+
subscript(key: String) -> String { // expected-error {{invalid redeclaration of 'subscript'}}
272+
get { a } // expected-error {{use of unresolved identifier 'a'}}
273+
set { b } // expected-error {{use of unresolved identifier 'b'}}
274+
}
275+
}
276+

0 commit comments

Comments
 (0)