Skip to content

Commit 9e4778e

Browse files
R-Camacholerno
andauthored
$stringify would handle parens incorrectly (#3316)
* $stringify would handle parens incorrectly Closes #3311 * Fix bug in the proper way. Add releasenotes. --------- Co-authored-by: Christoffer Lerno <christoffer@aegik.com>
1 parent 60be483 commit 9e4778e

3 files changed

Lines changed: 24 additions & 1 deletion

File tree

releasenotes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
### Stdlib changes
99

1010
### Fixes
11+
- `$stringify` would sometimes include parens.
1112

1213
## 0.8.1 Change list
1314

src/compiler/parse_expr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -720,7 +720,7 @@ static Expr *parse_ct_stringify(ParseContext *c, Expr *left, SourceLoc *lhs_star
720720
advance(c);
721721
CONSUME_OR_RET(TOKEN_LPAREN, poisoned_expr);
722722
ASSIGN_EXPR_OR_RET(Expr *inner, parse_expr(c), poisoned_expr);
723-
const char *end = c->lexer.lexing_start - 1;
723+
const char *end = c->span.offset + c->lexer.file_begin;
724724
CONSUME_OR_RET(TOKEN_RPAREN, poisoned_expr);
725725
if (inner->expr_kind == EXPR_HASH_IDENT || (inner->expr_kind == EXPR_VAARG))
726726
{
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// #target: macos-x64
2+
module test;
3+
import std::io;
4+
5+
fn void main()
6+
{
7+
io::printfn($stringify(asd) );
8+
io::printfn($stringify(asd ) );
9+
io::printfn($stringify(((((asd))))));
10+
io::printfn($stringify( (1 + 1) ));
11+
io::printfn($stringify("()"));
12+
io::printfn($stringify(")))" ) );
13+
}
14+
15+
/* #expect: test.ll
16+
17+
@.str = private unnamed_addr constant [4 x i8] c"asd\00", align 1
18+
@.str.1 = private unnamed_addr constant [6 x i8] c"asd \00", align 1
19+
@.str.2 = private unnamed_addr constant [12 x i8] c"((((asd))))\00", align 1
20+
@.str.3 = private unnamed_addr constant [10 x i8] c" (1 + 1) \00", align 1
21+
@.str.4 = private unnamed_addr constant [5 x i8] c"\22()\22\00", align 1
22+
@.str.5 = private unnamed_addr constant [7 x i8] c"\22)))\22 \00", align 1

0 commit comments

Comments
 (0)