hare

[hare] The Hare programming language
git clone https://git.torresjrjr.com/hare.git
Log | Files | Refs | README | LICENSE

commit 8896188829a00923d51bc8ec471bd138de5f965a
parent f81955048c5ca066067ee6c864756c148ef5d5f5
Author: Thomas Bracht Laumann Jespersen <t@laumann.xyz>
Date:   Sat, 19 Nov 2022 14:33:49 +0100

hare::parse: free lexer.comment to avoid duplication

The comment buffer in the lexer needs to be freed to avoid duplicating
line comments when parsing enum types.

Fixes: https://todo.sr.ht/~sircmpwn/hare/767
Signed-off-by: Thomas Bracht Laumann Jespersen <t@laumann.xyz>

Diffstat:
Mhare/parse/+test/types.ha | 9+++++++++
Mhare/parse/type.ha | 2++
2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/hare/parse/+test/types.ha b/hare/parse/+test/types.ha @@ -79,3 +79,12 @@ export type baz = (bat | foo::bar::baz | long_type_name | yet_another_very_long_ this_spans_multiple_lines | for_readability); "); }; + +@test fn enum_comments() void = { + roundtrip("type foo = enum { + A, // comment + B, + C, +}; +"); +}; diff --git a/hare/parse/type.ha b/hare/parse/type.ha @@ -431,6 +431,8 @@ fn enum_type(lexer: *lex::lexer) (ast::_type | error) = { if (linecomment != "") { free(comment); comment = strings::dup(linecomment); + free(lexer.comment); + lexer.comment = ""; }; case ltok::RBRACE => break; case => abort();