Skip to content

Commit 49ff38d

Browse files
committed
[CSDiag] Switch to using the ASPrinter rather than repeating logic
1 parent b9b1ea6 commit 49ff38d

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

lib/Sema/CSDiag.cpp

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -548,32 +548,21 @@ static bool diagnoseAmbiguity(ConstraintSystem &cs,
548548
}
549549

550550
static std::string getTypeListString(Type type) {
551-
// Assemble the parameter type list.
552-
auto tupleType = type->getAs<TupleType>();
553-
if (!tupleType) {
554-
if (auto PT = dyn_cast<ParenType>(type.getPointer()))
555-
type = PT->getUnderlyingType();
551+
std::string result;
556552

557-
return "(" + type->getString() + ")";
558-
}
553+
// Always make sure to have at least one set of parens
554+
bool forceParens =
555+
!type->is<TupleType>() && !isa<ParenType>(type.getPointer());
556+
if (forceParens)
557+
result.push_back('(');
559558

560-
std::string result = "(";
561-
for (auto field : tupleType->getElements()) {
562-
if (result.size() != 1)
563-
result += ", ";
564-
if (!field.getName().empty()) {
565-
result += field.getName().str();
566-
result += ": ";
567-
}
559+
llvm::raw_string_ostream OS(result);
560+
type->print(OS);
561+
OS.flush();
562+
563+
if (forceParens)
564+
result.push_back(')');
568565

569-
if (!field.isVararg())
570-
result += field.getType()->getString();
571-
else {
572-
result += field.getVarargBaseTy()->getString();
573-
result += "...";
574-
}
575-
}
576-
result += ")";
577566
return result;
578567
}
579568

test/Constraints/diagnostics.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -672,7 +672,7 @@ func overloadSetResultType(_ a : Int, b : Int) -> Int {
672672
// https://twitter.com/_jlfischer/status/712337382175952896
673673
// TODO: <rdar://problem/27391581> QoI: Nonsensical "binary operator '&&' cannot be applied to two 'Bool' operands"
674674
return a == b && 1 == 2 // expected-error {{binary operator '&&' cannot be applied to two 'Bool' operands}}
675-
// expected-note @-1 {{expected an argument list of type '(Bool, () throws -> Bool)'}}
675+
// expected-note @-1 {{expected an argument list of type '(Bool, @autoclosure () throws -> Bool)'}}
676676
}
677677

678678
// <rdar://problem/21523291> compiler error message for mutating immutable field is incorrect
@@ -736,7 +736,7 @@ extension Foo23752537 {
736736
// TODO: <rdar://problem/27391581> QoI: Nonsensical "binary operator '&&' cannot be applied to two 'Bool' operands"
737737
// expected-error @+1 {{binary operator '&&' cannot be applied to two 'Bool' operands}}
738738
return (self.title != other.title && self.message != other.message)
739-
// expected-note @-1 {{expected an argument list of type '(Bool, () throws -> Bool)'}}
739+
// expected-note @-1 {{expected an argument list of type '(Bool, @autoclosure () throws -> Bool)'}}
740740
}
741741
}
742742

test/attr/attr_noescape.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ struct S : P2 {
198198
func each(_ transform: @noescape (Int) -> ()) { // expected-warning{{@noescape is the default and is deprecated}} {{26-36=}}
199199
overloadedEach(self, // expected-error {{cannot invoke 'overloadedEach' with an argument list of type '(S, (Int) -> (), Int)'}}
200200
transform, 1)
201-
// expected-note @-2 {{overloads for 'overloadedEach' exist with these partially matching parameter lists: (O, (O.Element) -> (), T), (P, (P.Element) -> (), T)}}
201+
// expected-note @-2 {{overloads for 'overloadedEach' exist with these partially matching parameter lists: (O, @escaping (O.Element) -> (), T), (P, @escaping (P.Element) -> (), T)}}
202202
}
203203
}
204204

0 commit comments

Comments
 (0)