[Sema] printConstExprValue should consider negative signal when print number literals

This commit is contained in:
Luciano Almeida
2022-11-15 18:50:26 -03:00
parent ec29497c63
commit 4fb0e1c1f1
2 changed files with 22 additions and 1 deletions

View File

@@ -215,8 +215,12 @@ bool Expr::printConstExprValue(llvm::raw_ostream *OS,
}
case ExprKind::IntegerLiteral:
case ExprKind::FloatLiteral: {
auto digits = cast<NumberLiteralExpr>(E)->getDigitsText();
const auto *NE = cast<NumberLiteralExpr>(E);
auto digits = NE->getDigitsText();
assert(!digits.empty());
if (NE->getMinusLoc().isValid()) {
print("-");
}
print(digits);
return true;
}

View File

@@ -227,3 +227,20 @@ let _: [Int: String] = [
#column: "A", // expected-warning{{dictionary literal of type '[Int : String]' has duplicate entries for #column literal key}}
#column: "B" // expected-note{{duplicate key declared here}} {{3-16=}} {{227:15-16=}}
]
// https://github.com/apple/swift/issues/62117
_ = [
-1: "",
1: "",
]
_ = [
-1.0: "",
1.0: "",
]
_ = [
// expected-note@+1{{duplicate key declared}} {{3-9=}} {{9-10=}}
-1: "", // expected-warning{{dictionary literal of type '[Int : String]' has duplicate entries for integer literal key '-1'}}
-1: "", // expected-note{{duplicate key declared}} {{3-9=}} {{9-10=}}
]