Skip to content

Commit 9671dff

Browse files
authored
Merge pull request #4947 from rudkx/fix-27830834-swift-3.0-branch
Fix crash on typecheck failure in interpolated strings.
2 parents 485ccd6 + e2d93d6 commit 9671dff

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
@@ -3075,7 +3075,14 @@ namespace {
30753075

30763076
std::pair<bool, Expr *> walkToExprPre(Expr *expr) override {
30773077
TS->ExprTypes[expr] = expr->getType();
3078-
3078+
3079+
SWIFT_DEFER {
3080+
assert((!expr->getType() || !expr->getType()->hasTypeVariable()
3081+
// FIXME: We shouldn't allow these, either.
3082+
|| isa<LiteralExpr>(expr)) &&
3083+
"Type variable didn't get erased!");
3084+
};
3085+
30793086
// Preserve module expr type data to prevent further lookups.
30803087
if (auto *declRef = dyn_cast<DeclRefExpr>(expr))
30813088
if (isa<ModuleDecl>(declRef->getDecl()))
@@ -3086,17 +3093,13 @@ namespace {
30863093
if (isa<OtherConstructorDeclRefExpr>(expr))
30873094
return { false, expr };
30883095

3089-
// TypeExpr's are relabeled by CSGen.
3090-
if (isa<TypeExpr>(expr))
3091-
return { false, expr };
3092-
30933096
// If a literal has a Builtin.Int or Builtin.FP type on it already,
30943097
// then sema has already expanded out a call to
30953098
// Init.init(<builtinliteral>)
30963099
// and we don't want it to make
30973100
// Init.init(Init.init(<builtinliteral>))
30983101
// preserve the type info to prevent this from happening.
3099-
if (isa<LiteralExpr>(expr) &&
3102+
if (isa<LiteralExpr>(expr) && !isa<InterpolatedStringLiteralExpr>(expr) &&
31003103
!(expr->getType() && expr->getType()->is<ErrorType>()))
31013104
return { false, expr };
31023105

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)