Skip to content

Clang Importer: Set the ElementType of synthesized SubscriptDecls to the contextual generic type. #4125

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

Merged
merged 1 commit into from
Aug 9, 2016
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
1 change: 1 addition & 0 deletions lib/AST/ASTDumper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -726,6 +726,7 @@ namespace {
void visitSubscriptDecl(SubscriptDecl *SD) {
printCommon(SD, "subscript_decl");
OS << " storage_kind=" << getStorageKindName(SD->getStorageKind());
OS << " element=" << SD->getElementType()->getCanonicalType();
printAccessors(SD);
OS << ')';
}
Expand Down
5 changes: 4 additions & 1 deletion lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4832,6 +4832,9 @@ namespace {
auto elementTy
= getter->getInterfaceType()->castTo<AnyFunctionType>()->getResult()
->castTo<AnyFunctionType>()->getResult();
auto elementContextTy
= getter->getType()->castTo<AnyFunctionType>()->getResult()
->castTo<AnyFunctionType>()->getResult();

// Local function to mark the setter unavailable.
auto makeSetterUnavailable = [&] {
Expand Down Expand Up @@ -4934,7 +4937,7 @@ namespace {
getOverridableAccessibility(dc),
name, decl->getLoc(), bodyParams,
decl->getLoc(),
TypeLoc::withoutLoc(elementTy), dc);
TypeLoc::withoutLoc(elementContextTy),dc);

/// Record the subscript as an alternative declaration.
Impl.AlternateDecls[associateWithSetter ? setter : getter] = subscript;
Expand Down
11 changes: 11 additions & 0 deletions test/SILGen/Inputs/objc_bridged_generic_nonnull.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
@import Foundation;

@interface NonnullMembers<T> : NSObject

- (T _Nonnull) method;

@property (readonly) T _Nonnull property;

- (T _Nonnull)objectForKeyedSubscript:(id _Nonnull)key;

@end
11 changes: 11 additions & 0 deletions test/SILGen/objc_bridged_generic_nonnull.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// RUN: %target-swift-frontend -emit-silgen -verify -import-objc-header %S/Inputs/objc_bridged_generic_nonnull.h %s
// REQUIRES: objc_interop

public func test<T: AnyObject>(_ x: NonnullMembers<T>) -> T? {
var z: T?
z = x.method()
z = x.property
z = x.property
z = x[x]
_ = z
}