Skip to content

Commit 81091db

Browse files
committed
[NFC] Additional DeclNameRef auditing
1 parent 01f0eb2 commit 81091db

File tree

4 files changed

+17
-4
lines changed

4 files changed

+17
-4
lines changed

lib/Sema/CSGen.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3174,8 +3174,8 @@ namespace {
31743174
TVO_CanBindToNoEscape);
31753175
componentTypeVars.push_back(memberTy);
31763176
auto lookupName = kind == KeyPathExpr::Component::Kind::UnresolvedProperty
3177-
? DeclNameRef(component.getUnresolvedDeclName()) // FIXME: type change needed
3178-
: component.getDeclRef().getDecl()->createNameRef();
3177+
? component.getUnresolvedDeclName()
3178+
: component.getDeclRef().getDecl()->createNameRef(/*modSel=*/true);
31793179

31803180
auto refKind = lookupName.isSimpleName()
31813181
? FunctionRefKind::Unapplied
@@ -4195,9 +4195,13 @@ swift::resolveValueMember(DeclContext &DC, Type BaseTy, DeclName Name) {
41954195
ResolvedMemberResult Result;
41964196
ConstraintSystem CS(&DC, None);
41974197

4198+
// OK: By contract, `Name` should be derived from an existing Decl, not a
4199+
// name written by the user in source code. So when used as intended, we won't
4200+
// be dropping a module selector here.
4201+
DeclNameRef NameRef(Name);
41984202
// Look up all members of BaseTy with the given Name.
41994203
MemberLookupResult LookupResult = CS.performMemberLookup(
4200-
ConstraintKind::ValueMember, DeclNameRef(Name), BaseTy,
4204+
ConstraintKind::ValueMember, NameRef, BaseTy,
42014205
FunctionRefKind::SingleApply, CS.getConstraintLocator({}), false);
42024206

42034207
// Keep track of all the unviable members.

lib/Sema/CSSimplify.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6092,6 +6092,9 @@ ConstraintSystem::simplifyConstructionConstraint(
60926092
// variable T. T2 is the result type provided via the construction
60936093
// constraint itself.
60946094
addValueMemberConstraint(MetatypeType::get(valueType, getASTContext()),
6095+
// OK: simplifyConstructionConstraint() is only used
6096+
// for `T(...)` init calls, not `T.init(...)` calls,
6097+
// so there's no module selector on `init`.
60956098
DeclNameRef::createConstructor(),
60966099
memberType,
60976100
useDC, functionRefKind,
@@ -11165,7 +11168,9 @@ ConstraintSystem::simplifyRestrictedConstraintImpl(
1116511168
auto *memberTy = createTypeVariable(memberLoc, TVO_CanBindToNoEscape);
1116611169

1116711170
addValueMemberConstraint(MetatypeType::get(type2, getASTContext()),
11168-
DeclNameRef(DeclBaseName::createConstructor()),
11171+
// OK: Implicit conversion, no module selector to
11172+
// drop here.
11173+
DeclNameRef::createConstructor(),
1116911174
memberTy, DC, FunctionRefKind::DoubleApply,
1117011175
/*outerAlternatives=*/{}, memberLoc);
1117111176

lib/Sema/TypeCheckAttr.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1977,6 +1977,8 @@ SynthesizeMainFunctionRequest::evaluate(Evaluator &evaluator,
19771977
// mainType.main() from the entry point, and that would require fully
19781978
// type-checking the call to mainType.main().
19791979

1980+
// FIXME: resolveValueMember() is intended for IDEs--we should use something
1981+
// else.
19801982
auto resolution = resolveValueMember(
19811983
*declContext, nominal->getInterfaceType(), context.Id_main);
19821984

test/NameLookup/module_selector.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
// * Whether we handle access paths correctly
1010
// * Interaction with ClangImporter
1111
// * Cross-import overlays
12+
// * Key paths
13+
// * Key path dynamic member lookup
1214
//
1315
// It also might not cover all combinations of name lookup paths and inputs.
1416

0 commit comments

Comments
 (0)