Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't add constraints for invalid subscript declarations. #389

Merged
merged 1 commit into from
Dec 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion lib/Sema/CSGen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1517,8 +1517,11 @@ namespace {

Type visitSubscriptExpr(SubscriptExpr *expr) {
ValueDecl *decl = nullptr;
if (expr->hasDecl())
if (expr->hasDecl()) {
decl = expr->getDecl().getDecl();
if (decl->isInvalid())
return Type();
}
return addSubscriptConstraints(expr, expr->getBase(), expr->getIndex(),
decl);
}
Expand Down
15 changes: 15 additions & 0 deletions test/decl/subscript/subscripting.swift
Original file line number Diff line number Diff line change
Expand Up @@ -259,3 +259,18 @@ func testSubscript1(s2 : SubscriptTest2) {
let b = s2[1, "foo"] // expected-error {{cannot subscript a value of type 'SubscriptTest2' with an index of type '(Int, String)'}}
// expected-note @-1 {{expected an argument list of type '(String, String)'}}
}

// sr-114 & rdar://22007370

class Foo {
subscript(key: String) -> String { // expected-note {{'subscript' previously declared here}}
get { a } // expected-error {{use of unresolved identifier 'a'}}
set { b } // expected-error {{use of unresolved identifier 'b'}}
}

subscript(key: String) -> String { // expected-error {{invalid redeclaration of 'subscript'}}
get { a } // expected-error {{use of unresolved identifier 'a'}}
set { b } // expected-error {{use of unresolved identifier 'b'}}
}
}