Skip to content

Commit 4314721

Browse files
gh-163: Make STR operator reject invalid types.
1 parent d6ff4a2 commit 4314721

1 file changed

Lines changed: 5 additions & 9 deletions

File tree

src/builtins.c

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4983,8 +4983,8 @@ static Value builtin_base(Interpreter* interp, Value* args, int argc, Expr** arg
49834983
}
49844984

49854985
static Value builtin_str(Interpreter* interp, Value* args, int argc, Expr** arg_nodes, Env* env, int line, int col) {
4986-
(void)arg_nodes; (void)env; (void)interp; (void)line; (void)col;
4987-
4986+
(void)arg_nodes; (void)env;
4987+
49884988
if (args[0].type == VAL_STR) {
49894989
return value_str(args[0].as.s);
49904990
}
@@ -5003,13 +5003,9 @@ static Value builtin_str(Interpreter* interp, Value* args, int argc, Expr** arg_
50035003
free(s);
50045004
return v;
50055005
}
5006-
5007-
if (args[0].type == VAL_FUNC) {
5008-
char buf[64];
5009-
snprintf(buf, sizeof(buf), "<func %p>", (void*)args[0].as.func);
5010-
return value_str(buf);
5011-
}
5012-
return value_str("");
5006+
5007+
/* Per SPEC section 9.1.2, STR conversion only accepts BOOL, STR, INT, FLT. */
5008+
RUNTIME_ERROR(interp, "STR expects BOOL, STR, INT, or FLT", line, col);
50135009
}
50145010

50155011
// BYTES(INT: n, endian = "big"):TNS

0 commit comments

Comments
 (0)