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/parse.cff | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'src/parse.cff') 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