Skip to content

Commit e2d93d6

Browse files
committed
Fix crash on typecheck failure in interpolated strings.
We were attempting to clean up stray type variables before creating a new constraint system and moving forward with narrowing down the typecheck failure, but we were failing to remove type variables for interpolated strings. Fix that, as well as removing them from TypeExpr's, and add an assert that on exit from the pre-order visitor we don't have any type variables (except for literals that aren't interpolated strings, which I'm going to dig into further). Fixes rdar://problem/27830834 and SR-2716. (cherry picked from commit b44a93e)
1 parent 4dea103 commit e2d93d6

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3086,7 +3086,14 @@ namespace {
30863086

30873087
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
30883088
TS->ExprTypes[expr] = expr->getType();
3089-
3089+
3090+
SWIFT_DEFER {
3091+
assert((!expr->getType() || !expr->getType()->hasTypeVariable()
3092+
// FIXME: We shouldn't allow these, either.
3093+
|| isa<LiteralExpr>(expr)) &&
3094+
"Type variable didn't get erased!");
3095+
};
3096+
30903097
// Preserve module expr type data to prevent further lookups.
30913098
if (auto *declRef = dyn_cast<DeclRefExpr>(expr))
30923099
if (isa<ModuleDecl>(declRef->getDecl()))
@@ -3097,17 +3104,13 @@ namespace {
30973104
if (isa<OtherConstructorDeclRefExpr>(expr))
30983105
return { false, expr };
30993106

3100-
// TypeExpr's are relabeled by CSGen.
3101-
if (isa<TypeExpr>(expr))
3102-
return { false, expr };
3103-
31043107
// If a literal has a Builtin.Int or Builtin.FP type on it already,
31053108
// then sema has already expanded out a call to
31063109
// Init.init(<builtinliteral>)
31073110
// and we don't want it to make
31083111
// Init.init(Init.init(<builtinliteral>))
31093112
// preserve the type info to prevent this from happening.
3110-
if (isa<LiteralExpr>(expr) &&
3113+
if (isa<LiteralExpr>(expr) && !isa<InterpolatedStringLiteralExpr>(expr) &&
31113114
!(expr->getType() && expr->getType()->is<ErrorType>()))
31123115
return { false, expr };
31133116

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// RUN: %target-swift-frontend %s -parse -verify
2+
3+
var d = [String:String]()
4+
_ = "\(d.map{ [$0 : $0] })" // expected-error {{type of expression is ambiguous without more context}}

0 commit comments

Comments
 (0)