@@ -550,8 +550,8 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
550
550
if (typeContext->getSelfClassDecl ())
551
551
SelfType = DynamicSelfType::get (SelfType, Context);
552
552
SelfType = DC->mapTypeIntoContext (SelfType);
553
- return new (Context) TypeExpr ( TypeLoc ( new (Context)
554
- FixedTypeRepr (SelfType, Loc) ));
553
+ return new (Context)
554
+ TypeExpr ( new (Context) FixedTypeRepr (SelfType, Loc));
555
555
}
556
556
}
557
557
@@ -644,9 +644,14 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
644
644
D->getInterfaceType ());
645
645
}
646
646
647
- return TypeExpr::createForDecl (UDRE->getNameLoc (), D,
648
- Lookup[0 ].getDeclContext (),
649
- UDRE->isImplicit ());
647
+ auto *LookupDC = Lookup[0 ].getDeclContext ();
648
+ if (UDRE->isImplicit ()) {
649
+ return TypeExpr::createImplicitForDecl (
650
+ UDRE->getNameLoc (), D, LookupDC,
651
+ LookupDC->mapTypeIntoContext (D->getInterfaceType ()));
652
+ } else {
653
+ return TypeExpr::createForDecl (UDRE->getNameLoc (), D, LookupDC);
654
+ }
650
655
}
651
656
652
657
if (AllDeclRefs) {
@@ -715,13 +720,15 @@ Expr *TypeChecker::resolveDeclRefExpr(UnresolvedDeclRefExpr *UDRE,
715
720
if (AllMemberRefs) {
716
721
Expr *BaseExpr;
717
722
if (auto PD = dyn_cast<ProtocolDecl>(Base)) {
718
- BaseExpr = TypeExpr::createForDecl (UDRE->getNameLoc (),
719
- PD->getGenericParams ()->getParams ().front (),
720
- /* DC*/ nullptr ,
721
- /* isImplicit=*/ true );
723
+ auto selfParam = PD->getGenericParams ()->getParams ().front ();
724
+ BaseExpr = TypeExpr::createImplicitForDecl (
725
+ UDRE->getNameLoc (), selfParam,
726
+ /* DC*/ nullptr ,
727
+ DC->mapTypeIntoContext (selfParam->getInterfaceType ()));
722
728
} else if (auto NTD = dyn_cast<NominalTypeDecl>(Base)) {
723
- BaseExpr = TypeExpr::createForDecl (UDRE->getNameLoc (), NTD, BaseDC,
724
- /* isImplicit=*/ true );
729
+ BaseExpr = TypeExpr::createImplicitForDecl (
730
+ UDRE->getNameLoc (), NTD, BaseDC,
731
+ DC->mapTypeIntoContext (NTD->getInterfaceType ()));
725
732
} else {
726
733
BaseExpr = new (Context) DeclRefExpr (Base, UDRE->getNameLoc (),
727
734
/* Implicit=*/ true );
@@ -1383,15 +1390,15 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
1383
1390
if (Name.isSimpleName (getASTContext ().Id_Protocol )) {
1384
1391
auto *NewTypeRepr =
1385
1392
new (getASTContext ()) ProtocolTypeRepr (InnerTypeRepr, NameLoc);
1386
- return new (getASTContext ()) TypeExpr (TypeLoc ( NewTypeRepr, Type ()) );
1393
+ return new (getASTContext ()) TypeExpr (NewTypeRepr);
1387
1394
}
1388
1395
1389
1396
// Fold 'T.Type' into an existential metatype if 'T' is a protocol,
1390
1397
// or an ordinary metatype otherwise.
1391
1398
if (Name.isSimpleName (getASTContext ().Id_Type )) {
1392
1399
auto *NewTypeRepr =
1393
1400
new (getASTContext ()) MetatypeTypeRepr (InnerTypeRepr, NameLoc);
1394
- return new (getASTContext ()) TypeExpr (TypeLoc ( NewTypeRepr, Type ()) );
1401
+ return new (getASTContext ()) TypeExpr (NewTypeRepr);
1395
1402
}
1396
1403
1397
1404
// Fold 'T.U' into a nested type.
@@ -1486,7 +1493,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1486
1493
1487
1494
auto *NewTypeRepr =
1488
1495
new (getASTContext ()) OptionalTypeRepr (InnerTypeRepr, QuestionLoc);
1489
- return new (getASTContext ()) TypeExpr (TypeLoc ( NewTypeRepr, Type ()) );
1496
+ return new (getASTContext ()) TypeExpr (NewTypeRepr);
1490
1497
}
1491
1498
1492
1499
// Fold T! into an IUO type when T is a TypeExpr.
@@ -1502,7 +1509,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1502
1509
auto *NewTypeRepr = new (getASTContext ())
1503
1510
ImplicitlyUnwrappedOptionalTypeRepr (InnerTypeRepr,
1504
1511
FVE->getExclaimLoc ());
1505
- return new (getASTContext ()) TypeExpr (TypeLoc ( NewTypeRepr, Type ()) );
1512
+ return new (getASTContext ()) TypeExpr (NewTypeRepr);
1506
1513
}
1507
1514
1508
1515
// Fold (T) into a type T with parens around it.
@@ -1517,7 +1524,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1517
1524
1518
1525
auto *NewTypeRepr = TupleTypeRepr::create (getASTContext (), InnerTypeRepr,
1519
1526
PE->getSourceRange ());
1520
- return new (getASTContext ()) TypeExpr (TypeLoc ( NewTypeRepr, Type ()) );
1527
+ return new (getASTContext ()) TypeExpr (NewTypeRepr);
1521
1528
}
1522
1529
1523
1530
// Fold a tuple expr like (T1,T2) into a tuple type (T1,T2).
@@ -1550,7 +1557,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1550
1557
}
1551
1558
auto *NewTypeRepr = TupleTypeRepr::create (
1552
1559
getASTContext (), Elts, TE->getSourceRange (), SourceLoc (), Elts.size ());
1553
- return new (getASTContext ()) TypeExpr (TypeLoc ( NewTypeRepr, Type ()) );
1560
+ return new (getASTContext ()) TypeExpr (NewTypeRepr);
1554
1561
}
1555
1562
1556
1563
@@ -1566,7 +1573,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1566
1573
auto *NewTypeRepr = new (getASTContext ())
1567
1574
ArrayTypeRepr (TyExpr->getTypeRepr (),
1568
1575
SourceRange (AE->getLBracketLoc (), AE->getRBracketLoc ()));
1569
- return new (getASTContext ()) TypeExpr (TypeLoc ( NewTypeRepr, Type ()) );
1576
+ return new (getASTContext ()) TypeExpr (NewTypeRepr);
1570
1577
}
1571
1578
1572
1579
// Fold [K : V] into a dictionary type.
@@ -1607,7 +1614,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1607
1614
keyTypeRepr, valueTypeRepr,
1608
1615
/* FIXME:colonLoc=*/ SourceLoc (),
1609
1616
SourceRange (DE->getLBracketLoc (), DE->getRBracketLoc ()));
1610
- return new (getASTContext ()) TypeExpr (TypeLoc ( NewTypeRepr, Type ()) );
1617
+ return new (getASTContext ()) TypeExpr (NewTypeRepr);
1611
1618
}
1612
1619
1613
1620
// Reinterpret arrow expr T1 -> T2 as function type.
@@ -1699,7 +1706,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1699
1706
auto NewTypeRepr = new (ctx)
1700
1707
FunctionTypeRepr (nullptr , ArgsTypeRepr, AE->getThrowsLoc (),
1701
1708
AE->getArrowLoc (), ResultTypeRepr);
1702
- return new (ctx) TypeExpr (TypeLoc ( NewTypeRepr, Type ()) );
1709
+ return new (ctx) TypeExpr (NewTypeRepr);
1703
1710
}
1704
1711
1705
1712
// Fold 'P & Q' into a composition type
@@ -1751,7 +1758,7 @@ TypeExpr *PreCheckExpression::simplifyTypeExpr(Expr *E) {
1751
1758
auto CompRepr = CompositionTypeRepr::create (getASTContext (), Types,
1752
1759
lhsExpr->getStartLoc (),
1753
1760
binaryExpr->getSourceRange ());
1754
- return new (getASTContext ()) TypeExpr (TypeLoc ( CompRepr, Type ()) );
1761
+ return new (getASTContext ()) TypeExpr (CompRepr);
1755
1762
}
1756
1763
}
1757
1764
@@ -1926,38 +1933,35 @@ Expr *PreCheckExpression::simplifyTypeConstructionWithLiteralArg(Expr *E) {
1926
1933
if (!protocol)
1927
1934
return nullptr ;
1928
1935
1929
- Type type ;
1930
- if (typeExpr->getTypeLoc (). wasValidated ()) {
1931
- type = typeExpr->getTypeLoc (). getType ( );
1936
+ TypeLoc typeLoc ;
1937
+ if (auto precheckedTy = typeExpr->getInstanceType ()) {
1938
+ typeLoc = TypeLoc ( typeExpr->getTypeRepr (), precheckedTy );
1932
1939
} else {
1933
1940
TypeResolutionOptions options (TypeResolverContext::InExpression);
1934
1941
options |= TypeResolutionFlags::AllowUnboundGenerics;
1935
1942
1936
- auto & typeLoc = typeExpr->getTypeLoc ( );
1943
+ typeLoc = TypeLoc ( typeExpr->getTypeRepr (), Type () );
1937
1944
bool hadError = TypeChecker::validateType (
1938
1945
getASTContext (), typeLoc, TypeResolution::forContextual (DC), options);
1939
1946
1940
1947
if (hadError)
1941
1948
return nullptr ;
1942
-
1943
- type = typeLoc.getType ();
1944
1949
}
1945
1950
1946
- if (!type || !type ->getAnyNominal ())
1951
+ if (!typeLoc. getType () || !typeLoc. getType () ->getAnyNominal ())
1947
1952
return nullptr ;
1948
1953
1949
1954
// Don't bother to convert deprecated selector syntax.
1950
1955
if (auto selectorTy = getASTContext ().getSelectorType ()) {
1951
- if (type ->isEqual (selectorTy))
1956
+ if (typeLoc. getType () ->isEqual (selectorTy))
1952
1957
return nullptr ;
1953
1958
}
1954
1959
1955
- auto *NTD = type ->getAnyNominal ();
1960
+ auto *NTD = typeLoc. getType () ->getAnyNominal ();
1956
1961
SmallVector<ProtocolConformance *, 2 > conformances;
1957
1962
return NTD->lookupConformance (DC->getParentModule (), protocol, conformances)
1958
1963
? CoerceExpr::forLiteralInit (getASTContext (), argExpr,
1959
- call->getSourceRange (),
1960
- typeExpr->getTypeLoc ())
1964
+ call->getSourceRange (), typeLoc)
1961
1965
: nullptr ;
1962
1966
}
1963
1967
0 commit comments