Skip to content

Commit 56ccf6e

Browse files
committed
---
yaml --- r: 2787 b: refs/heads/master c: c4e9d8f h: refs/heads/master i: 2785: 576dc0c 2783: fcf0626 v: v3
1 parent a190996 commit 56ccf6e

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 1b29892b5b09f7f69150e1e8eaab2b3c8a12b163
2+
refs/heads/master: c4e9d8fb911a2e70162c7f61ac70e11c2f604650

trunk/src/comp/front/extfmt.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,7 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast::expr] args)
499499
auto sp = args.(0).span;
500500
auto n = 0u;
501501
auto tmp_expr = make_new_str(p, sp, "");
502+
auto nargs = vec::len[@ast::expr](args);
502503

503504
for (piece pc in pieces) {
504505
alt (pc) {
@@ -507,7 +508,7 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast::expr] args)
507508
tmp_expr = make_add_expr(p, sp, tmp_expr, s_expr);
508509
}
509510
case (piece_conv(?conv)) {
510-
if (n >= vec::len[@ast::expr](args)) {
511+
if (n >= nargs) {
511512
log_err "too many conversions in #fmt string";
512513
fail;
513514
}
@@ -524,6 +525,13 @@ fn pieces_to_expr(parser p, vec[piece] pieces, vec[@ast::expr] args)
524525
}
525526
}
526527

528+
auto expected_nargs = n + 1u; // n conversions + the fmt string
529+
if (expected_nargs < nargs) {
530+
log_err #fmt("too many arguments to #fmt. found %u, expected %u",
531+
nargs, expected_nargs);
532+
fail;
533+
}
534+
527535
// TODO: Remove this debug logging
528536
// log "dumping expanded ast:";
529537
// log pretty::print_expr(tmp_expr);
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// xfail-stage0
2+
// error-pattern:too many arguments
3+
4+
use std;
5+
6+
fn main() {
7+
auto s = #fmt("%s", "test", "test");
8+
}

0 commit comments

Comments
 (0)