diff options
| author | 2022-09-01 07:32:57 +0200 | |
|---|---|---|
| committer | 2022-09-01 07:32:57 +0200 | |
| commit | 8e85f9adcf63aefc0c8d1b825ad2d4a35584551d (patch) | |
| tree | f7d51dba2bbe5d88c82efa6a8c589c181abaa968 /src | |
| parent | ef0f3688497c4315e90f5aa19820524c1c100d09 (diff) | |
disallow mutating elements of const array
Diffstat (limited to 'src')
| -rw-r--r-- | src/cffc.hff | 2 | ||||
| -rw-r--r-- | src/parse.cff | 8 |
2 files changed, 7 insertions, 3 deletions
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) { |