Skip to content

[CSApply] Fix a case where CSApply produced an invalid DeclRefExpr #31398

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
Apr 29, 2020
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
24 changes: 12 additions & 12 deletions lib/Sema/CSApply.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1030,6 +1030,18 @@ namespace {
// Build a member reference.
auto memberRef = resolveConcreteDeclRef(member, memberLocator);

// If we're referring to a member type, it's just a type
// reference.
if (auto *TD = dyn_cast<TypeDecl>(member)) {
Type refType = simplifyType(openedType);
auto ref = TypeExpr::createForDecl(memberLoc, TD, cs.DC);
cs.setType(ref, refType);
auto *result = new (context) DotSyntaxBaseIgnoredExpr(
base, dotLoc, ref, refType);
cs.setType(result, refType);
return result;
}

// If we're referring to the member of a module, it's just a simple
// reference.
if (baseTy->is<ModuleType>()) {
Expand All @@ -1043,18 +1055,6 @@ namespace {
return forceUnwrapIfExpected(DSBI, choice, memberLocator);
}

// If we're referring to a member type, it's just a type
// reference.
if (auto *TD = dyn_cast<TypeDecl>(member)) {
Type refType = simplifyType(openedType);
auto ref = TypeExpr::createForDecl(memberLoc, TD, cs.DC);
cs.setType(ref, refType);
auto *result = new (context) DotSyntaxBaseIgnoredExpr(
base, dotLoc, ref, refType);
cs.setType(result, refType);
return result;
}

bool isUnboundInstanceMember =
(!baseIsInstance && member->isInstanceMember());
bool isPartialApplication = shouldBuildCurryThunk(choice, baseIsInstance);
Expand Down
4 changes: 4 additions & 0 deletions test/Constraints/Inputs/imported_type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#import <Foundation/Foundation.h>

@interface Data
@end
9 changes: 9 additions & 0 deletions test/Constraints/invalid_decl_ref.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// RUN: %target-swift-frontend -module-name SomeModule -typecheck -verify -dump-ast -import-objc-header %S/Inputs/imported_type.h %s | %FileCheck %s

// REQUIRES: objc_interop

import Foundation

// CHECK: declref_expr type='module<SomeModule>'
// CHECK-NEXT: type_expr type='Data.Type'
let type = SomeModule.Data.self
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@brentdax You might be interested in this example because, from how @hborla described this to me it appears that SomeModule.Data lookup would produce multiple results here - one for SomeModule.Data and one for Foundation.Data which seems like a bug in shadowing resolution?