From 8e85f9adcf63aefc0c8d1b825ad2d4a35584551d Mon Sep 17 00:00:00 2001 From: lemon Date: Thu, 1 Sep 2022 07:32:57 +0200 Subject: disallow mutating elements of const array --- src/cffc.hff | 2 +- src/parse.cff | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/cffc.hff b/src/cffc.hff index 7338b8a..135e8d8 100644 --- a/src/cffc.hff +++ b/src/cffc.hff @@ -395,7 +395,7 @@ struct Targ { } // parse.cff -extern static keyword2str [NUM_KEYWORDS]*const u8; +extern static const keyword2str [NUM_KEYWORDS]*const u8; extern fn parser_init(*Parser, path *const u8) void; extern fn parse(*Parser) [#]Decl; diff --git a/src/parse.cff b/src/parse.cff index d1027da..f5beb23 100644 --- a/src/parse.cff +++ b/src/parse.cff @@ -140,7 +140,7 @@ fn eatspaces(P *Parser) void { } // !sorted -extern static keyword2str [NUM_KEYWORDS]*const u8 = { +extern static const keyword2str [NUM_KEYWORDS]*const u8 = { "alignof", "and", "as", "bitfield", "break", "case", "const", "continue", "def", "defer", "defmacro", "do", "else", "enum", "extern", "fn", @@ -1710,7 +1710,11 @@ fn pexpostfix(P *Parser) Expr { ex = { tok.loc, mkslicetype(childtype(lhs.ty)), .u: :Slice { lhs, rhs, end }}; } else { lexexpect(P, ']'); - ex = { tok.loc, childtype(lhs.ty), .u: :Index { lhs, rhs }}; + let ty = childtype(lhs.ty); + if lhs.ty->is(:Arr) and lhs.ty.konst { + ty = constify(ty); + } + ex = { tok.loc, ty, .u: :Index { lhs, rhs }}; } case lexmatch(P, &tok, '++') or lexmatch(P, &tok, '--'); if !isnumtype(ex.ty) and !ex.ty->is(:Ptr) { -- cgit v1.2.3