Skip to content

Commit 5e7bafc

Browse files
authored
Merge pull request #33060 from hborla/remove-csgen-literal-hack
[CSGen] Don't merge type variables for literals in `computeFavoredTypeForExpr`
2 parents d6ea573 + 71b3ac4 commit 5e7bafc

File tree

2 files changed

+3
-43
lines changed

2 files changed

+3
-43
lines changed

lib/Sema/CSGen.cpp

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,6 @@ namespace {
8484
unsigned haveStringLiteral : 1;
8585

8686
llvm::SmallSet<TypeBase*, 16> collectedTypes;
87-
88-
llvm::SmallVector<TypeVariableType *, 16> intLiteralTyvars;
89-
llvm::SmallVector<TypeVariableType *, 16> floatLiteralTyvars;
90-
llvm::SmallVector<TypeVariableType *, 16> stringLiteralTyvars;
91-
9287
llvm::SmallVector<BinaryExpr *, 4> binaryExprs;
9388

9489
LinkedTypeInfo() {
@@ -188,35 +183,16 @@ namespace {
188183

189184
if (isa<IntegerLiteralExpr>(expr)) {
190185
LTI.haveIntLiteral = true;
191-
auto tyvar = CS.getType(expr)->getAs<TypeVariableType>();
192-
193-
if (tyvar) {
194-
LTI.intLiteralTyvars.push_back(tyvar);
195-
}
196-
197186
return { false, expr };
198187
}
199188

200189
if (isa<FloatLiteralExpr>(expr)) {
201190
LTI.haveFloatLiteral = true;
202-
auto tyvar = CS.getType(expr)->getAs<TypeVariableType>();
203-
204-
if (tyvar) {
205-
LTI.floatLiteralTyvars.push_back(tyvar);
206-
}
207-
208191
return { false, expr };
209192
}
210193

211194
if (isa<StringLiteralExpr>(expr)) {
212195
LTI.haveStringLiteral = true;
213-
214-
auto tyvar = CS.getType(expr)->getAs<TypeVariableType>();
215-
216-
if (tyvar) {
217-
LTI.stringLiteralTyvars.push_back(tyvar);
218-
}
219-
220196
return { false, expr };
221197
}
222198

@@ -339,22 +315,6 @@ namespace {
339315

340316
expr->walk(LinkedExprAnalyzer(lti, CS));
341317

342-
auto mergeTypeVariables = [&](ArrayRef<TypeVariableType *> typeVars) {
343-
if (typeVars.size() < 2)
344-
return;
345-
346-
auto rep1 = CS.getRepresentative(typeVars.front());
347-
for (unsigned i = 1, n = typeVars.size(); i != n; ++i) {
348-
auto rep2 = CS.getRepresentative(typeVars[i]);
349-
if (rep1 != rep2)
350-
CS.mergeEquivalenceClasses(rep1, rep2, /*updateWorkList*/ false);
351-
}
352-
};
353-
354-
mergeTypeVariables(lti.intLiteralTyvars);
355-
mergeTypeVariables(lti.floatLiteralTyvars);
356-
mergeTypeVariables(lti.stringLiteralTyvars);
357-
358318
if (lti.collectedTypes.size() == 1) {
359319
// TODO: Compute the BCT.
360320

test/stdlib/UnicodeScalarDiagnostics.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ func isString(_ s: inout String) {}
88
func test_UnicodeScalarDoesNotImplementArithmetic(_ us: UnicodeScalar, i: Int) {
99
var a1 = "a" + "b" // OK
1010
isString(&a1)
11-
let a2 = "a" - "b" // expected-error {{binary operator '-' cannot be applied to two 'String' operands}}
12-
let a3 = "a" * "b" // expected-error {{binary operator '*' cannot be applied to two 'String' operands}}
13-
let a4 = "a" / "b" // expected-error {{binary operator '/' cannot be applied to two 'String' operands}}
11+
let a2 = "a" - "b" // expected-error {{binary operator '-' cannot be applied to two 'String' operands}} expected-note {{}}
12+
let a3 = "a" * "b" // expected-error {{binary operator '*' cannot be applied to two 'String' operands}} expected-note {{}}
13+
let a4 = "a" / "b" // expected-error {{binary operator '/' cannot be applied to two 'String' operands}} expected-note {{}}
1414

1515
let b1 = us + us // expected-error {{binary operator '+' cannot be applied to two 'UnicodeScalar' (aka 'Unicode.Scalar') operands}}
1616
let b2 = us - us // expected-error {{binary operator '-' cannot be applied to two 'UnicodeScalar' (aka 'Unicode.Scalar') operands}}

0 commit comments

Comments
 (0)