@@ -113,8 +113,11 @@ filterForEnumElement(DeclContext *DC, SourceLoc UseLoc,
113
113
114
114
// / Find an unqualified enum element.
115
115
static EnumElementDecl *
116
- lookupUnqualifiedEnumMemberElement (DeclContext *DC,
117
- Identifier name, SourceLoc UseLoc) {
116
+ lookupUnqualifiedEnumMemberElement (DeclContext *DC, DeclName name,
117
+ SourceLoc UseLoc) {
118
+ // FIXME: We should probably pay attention to argument labels someday.
119
+ name = name.getBaseName ();
120
+
118
121
auto lookupOptions = defaultUnqualifiedLookupOptions;
119
122
lookupOptions |= NameLookupFlags::KnownPrivate;
120
123
auto lookup =
@@ -126,10 +129,13 @@ lookupUnqualifiedEnumMemberElement(DeclContext *DC,
126
129
// / Find an enum element in an enum type.
127
130
static EnumElementDecl *
128
131
lookupEnumMemberElement (DeclContext *DC, Type ty,
129
- Identifier name, SourceLoc UseLoc) {
132
+ DeclName name, SourceLoc UseLoc) {
130
133
if (!ty->mayHaveMembers ())
131
134
return nullptr ;
132
135
136
+ // FIXME: We should probably pay attention to argument labels someday.
137
+ name = name.getBaseName ();
138
+
133
139
// Look up the case inside the enum.
134
140
// FIXME: We should be able to tell if this is a private lookup.
135
141
NameLookupOptions lookupOptions = defaultMemberLookupOptions;
@@ -440,10 +446,9 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,
440
446
if (ume->getName ().getBaseName ().isSpecial ())
441
447
return nullptr ;
442
448
443
- // FIXME: Compound names.
444
449
return new (Context)
445
- EnumElementPattern (ume->getDotLoc (), ume->getNameLoc (). getBaseNameLoc (),
446
- ume-> getName (). getBaseIdentifier (), subPattern, ume);
450
+ EnumElementPattern (ume->getDotLoc (), ume->getNameLoc (), ume-> getName (),
451
+ subPattern, ume);
447
452
}
448
453
449
454
// Member syntax 'T.Element' forms a pattern if 'T' is an enum and the
@@ -467,20 +472,17 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,
467
472
if (!enumDecl)
468
473
return nullptr ;
469
474
470
- // FIXME: Argument labels?
471
475
EnumElementDecl *referencedElement
472
- = lookupEnumMemberElement (DC, ty, ude->getName ().getBaseIdentifier (),
473
- ude->getLoc ());
476
+ = lookupEnumMemberElement (DC, ty, ude->getName (), ude->getLoc ());
474
477
if (!referencedElement)
475
478
return nullptr ;
476
479
477
480
// Build a TypeRepr from the head of the full path.
478
- // FIXME: Compound names.
479
481
TypeLoc loc (repr);
480
482
loc.setType (ty);
481
483
return new (Context) EnumElementPattern (
482
- loc, ude->getDotLoc (), ude->getNameLoc (). getBaseNameLoc (),
483
- ude-> getName (). getBaseIdentifier (), referencedElement, nullptr );
484
+ loc, ude->getDotLoc (), ude->getNameLoc (), ude-> getName (),
485
+ referencedElement, nullptr );
484
486
}
485
487
486
488
// A DeclRef 'E' that refers to an enum element forms an EnumElementPattern.
@@ -492,8 +494,8 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,
492
494
// Use the type of the enum from context.
493
495
TypeLoc loc = TypeLoc::withoutLoc (
494
496
elt->getParentEnum ()->getDeclaredTypeInContext ());
495
- return new (Context) EnumElementPattern (loc, SourceLoc (), de->getLoc (),
496
- elt->getName (), elt, nullptr );
497
+ return new (Context) EnumElementPattern (loc, SourceLoc (), de->getNameLoc (),
498
+ elt->createNameRef (), elt, nullptr );
497
499
}
498
500
Pattern *visitUnresolvedDeclRefExpr (UnresolvedDeclRefExpr *ude) {
499
501
// FIXME: This shouldn't be needed. It is only necessary because of the
@@ -502,15 +504,14 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,
502
504
//
503
505
// Try looking up an enum element in context.
504
506
if (EnumElementDecl *referencedElement
505
- = lookupUnqualifiedEnumMemberElement (DC,
506
- ude->getName ().getBaseIdentifier (),
507
+ = lookupUnqualifiedEnumMemberElement (DC, ude->getName (),
507
508
ude->getLoc ())) {
508
509
auto *enumDecl = referencedElement->getParentEnum ();
509
510
auto enumTy = enumDecl->getDeclaredTypeInContext ();
510
511
TypeLoc loc = TypeLoc::withoutLoc (enumTy);
511
512
512
513
return new (Context) EnumElementPattern (
513
- loc, SourceLoc (), ude->getLoc (), ude->getName (). getBaseIdentifier (),
514
+ loc, SourceLoc (), ude->getNameLoc (), ude->getName (),
514
515
referencedElement, nullptr );
515
516
}
516
517
@@ -585,8 +586,9 @@ class ResolvePattern : public ASTVisitor<ResolvePattern,
585
586
586
587
auto *subPattern = getSubExprPattern (ce->getArg ());
587
588
return new (Context) EnumElementPattern (
588
- loc, SourceLoc (), tailComponent->getIdLoc (),
589
- tailComponent->getIdentifier (), referencedElement, subPattern);
589
+ loc, SourceLoc (), DeclNameLoc (tailComponent->getIdLoc ()),
590
+ tailComponent->getIdentifier (), referencedElement,
591
+ subPattern);
590
592
}
591
593
};
592
594
@@ -1131,8 +1133,9 @@ bool TypeChecker::coercePatternToType(Pattern *&P, TypeResolution resolution,
1131
1133
if (auto *NLE = dyn_cast<NilLiteralExpr>(EP->getSubExpr ())) {
1132
1134
auto *NoneEnumElement = Context.getOptionalNoneDecl ();
1133
1135
P = new (Context) EnumElementPattern (TypeLoc::withoutLoc (type),
1134
- NLE->getLoc (), NLE->getLoc (),
1135
- NoneEnumElement->getName (),
1136
+ NLE->getLoc (),
1137
+ DeclNameLoc (NLE->getLoc ()),
1138
+ NoneEnumElement->getFullName (),
1136
1139
NoneEnumElement, nullptr , false );
1137
1140
return TypeChecker::coercePatternToType (P, resolution, type, options);
1138
1141
}
@@ -1166,8 +1169,8 @@ bool TypeChecker::coercePatternToType(Pattern *&P, TypeResolution resolution,
1166
1169
auto some = Context.getOptionalDecl ()->getUniqueElement (/* hasVal*/ true );
1167
1170
sub = new (Context) EnumElementPattern (TypeLoc (),
1168
1171
IP->getStartLoc (),
1169
- IP->getEndLoc (),
1170
- some->getName (),
1172
+ DeclNameLoc ( IP->getEndLoc () ),
1173
+ some->getFullName (),
1171
1174
nullptr , sub,
1172
1175
/* Implicit=*/ true );
1173
1176
}
@@ -1251,14 +1254,17 @@ bool TypeChecker::coercePatternToType(Pattern *&P, TypeResolution resolution,
1251
1254
// isn't a static VarDecl, so the existing mechanics in
1252
1255
// extractEnumElement won't work.
1253
1256
if (type->getAnyNominal () == Context.getOptionalDecl ()) {
1254
- if (EEP->getName ().str () == " None" ||
1255
- EEP->getName ().str () == " Some" ) {
1257
+ if (EEP->getName ().isSimpleName ( " None" ) ||
1258
+ EEP->getName ().isSimpleName ( " Some" ) ) {
1256
1259
SmallString<4 > Rename;
1257
- camel_case::toLowercaseWord (EEP->getName ().str (), Rename);
1260
+ camel_case::toLowercaseWord (EEP->getName ()
1261
+ .getBaseIdentifier ().str (),
1262
+ Rename);
1258
1263
diags.diagnose (
1259
1264
EEP->getLoc (), diag::availability_decl_unavailable_rename,
1260
- /* "getter" prefix*/ 2 , EEP->getName (), /* replaced*/ false ,
1261
- /* special kind*/ 0 , Rename.str (), /* message*/ StringRef ())
1265
+ /* "getter" prefix*/ 2 , EEP->getName ().getBaseName (),
1266
+ /* replaced*/ false , /* special kind*/ 0 , Rename.str (),
1267
+ /* message*/ StringRef ())
1262
1268
.fixItReplace (EEP->getLoc (), Rename.str ());
1263
1269
1264
1270
return true ;
@@ -1288,7 +1294,7 @@ bool TypeChecker::coercePatternToType(Pattern *&P, TypeResolution resolution,
1288
1294
} else {
1289
1295
diags.diagnose (EEP->getLoc (),
1290
1296
diag::enum_element_pattern_member_not_found,
1291
- EEP->getName (). str () , type);
1297
+ EEP->getName (), type);
1292
1298
return true ;
1293
1299
}
1294
1300
}
@@ -1341,7 +1347,7 @@ bool TypeChecker::coercePatternToType(Pattern *&P, TypeResolution resolution,
1341
1347
} else {
1342
1348
diags.diagnose (EEP->getLoc (),
1343
1349
diag::enum_element_pattern_not_member_of_enum,
1344
- EEP->getName (). str () , type);
1350
+ EEP->getName (), type);
1345
1351
return true ;
1346
1352
}
1347
1353
}
0 commit comments