|
21 | 21 | #include "MiscDiagnostics.h"
|
22 | 22 | #include "OpenedExistentials.h"
|
23 | 23 | #include "TypeCheckConcurrency.h"
|
| 24 | +#include "TypeCheckEmbedded.h" |
24 | 25 | #include "TypeCheckMacros.h"
|
25 | 26 | #include "TypeCheckProtocol.h"
|
26 | 27 | #include "TypeCheckType.h"
|
@@ -924,8 +925,9 @@ namespace {
|
924 | 925 | /// \returns An OpaqueValueExpr that provides a reference to the value
|
925 | 926 | /// stored within the expression or its metatype (if the base was a
|
926 | 927 | /// metatype).
|
927 |
| - Expr *openExistentialReference(Expr *base, ExistentialArchetypeType *archetype, |
928 |
| - ValueDecl *member) { |
| 928 | + Expr *openExistentialReference(Expr *base, |
| 929 | + ExistentialArchetypeType *archetype, |
| 930 | + ValueDecl *member, SourceLoc memberLoc) { |
929 | 931 | assert(archetype && "archetype not already opened?");
|
930 | 932 |
|
931 | 933 | // Dig out the base type.
|
@@ -955,6 +957,11 @@ namespace {
|
955 | 957 |
|
956 | 958 | assert(baseTy->isAnyExistentialType() && "Type must be existential");
|
957 | 959 |
|
| 960 | + // Embedded Swift has limitations on the use of generic members of |
| 961 | + // existentials. Diagnose them here. |
| 962 | + diagnoseGenericMemberOfExistentialInEmbedded( |
| 963 | + dc, memberLoc, baseTy, member); |
| 964 | + |
958 | 965 | // If the base was an lvalue but it will only be treated as an
|
959 | 966 | // rvalue, turn the base into an rvalue now. This results in
|
960 | 967 | // better SILGen.
|
@@ -1983,7 +1990,8 @@ namespace {
|
1983 | 1990 | (!member->getDeclContext()->getSelfProtocolDecl() &&
|
1984 | 1991 | baseIsInstance && member->isInstanceMember())) {
|
1985 | 1992 | // Open the existential before performing the member reference.
|
1986 |
| - base = openExistentialReference(base, knownOpened->second, member); |
| 1993 | + base = openExistentialReference(base, knownOpened->second, member, |
| 1994 | + memberLoc.getBaseNameLoc()); |
1987 | 1995 | baseTy = baseOpenedTy;
|
1988 | 1996 | selfTy = baseTy;
|
1989 | 1997 | openedExistential = true;
|
@@ -2490,7 +2498,8 @@ namespace {
|
2490 | 2498 | auto memberLoc = cs.getCalleeLocator(cs.getConstraintLocator(locator));
|
2491 | 2499 | auto knownOpened = solution.OpenedExistentialTypes.find(memberLoc);
|
2492 | 2500 | if (knownOpened != solution.OpenedExistentialTypes.end()) {
|
2493 |
| - base = openExistentialReference(base, knownOpened->second, subscript); |
| 2501 | + base = openExistentialReference(base, knownOpened->second, subscript, |
| 2502 | + args->getLoc()); |
2494 | 2503 | baseTy = knownOpened->second;
|
2495 | 2504 | }
|
2496 | 2505 |
|
@@ -6551,7 +6560,7 @@ ArgumentList *ExprRewriter::coerceCallArguments(
|
6551 | 6560 | cs.getConstraintLocator(argLoc));
|
6552 | 6561 | if (knownOpened != solution.OpenedExistentialTypes.end()) {
|
6553 | 6562 | argExpr = openExistentialReference(
|
6554 |
| - argExpr, knownOpened->second, callee.getDecl()); |
| 6563 | + argExpr, knownOpened->second, callee.getDecl(), apply->getLoc()); |
6555 | 6564 | argType = cs.getType(argExpr);
|
6556 | 6565 | }
|
6557 | 6566 | }
|
|
0 commit comments