diff --git a/lib/std/encoding/base64.c3 b/lib/std/encoding/base64.c3 index 1b962cd8b..4c9cf4ee0 100644 --- a/lib/std/encoding/base64.c3 +++ b/lib/std/encoding/base64.c3 @@ -220,7 +220,7 @@ fn usz! Base64Decoder.decode(&self, char[] src, char[] dst) if (trailing == 0) return dn; - src = src[^trailing:]; + src = src[^trailing..]; char c0 = self.reverse[src[0]]; char c1 = self.reverse[src[1]]; if (c0 == self.invalid || c1 == self.invalid) return Base64Error.INVALID_PADDING?; diff --git a/releasenotes.md b/releasenotes.md index 5b0775018..a32b6a834 100644 --- a/releasenotes.md +++ b/releasenotes.md @@ -56,6 +56,7 @@ - Default visibility can be overridden per module compile unit. Eg `module foo @private`. - Optimized macro codegen for -O0. - Addition of unary `+`. +- Remove possibility to elide length when using ':' for slices. - Remove the `:` and `;` used in $if, $switch etc. - Faults have an ordinal. - Generic module contracts. diff --git a/src/compiler/parse_expr.c b/src/compiler/parse_expr.c index a6071c618..f9577dd67 100644 --- a/src/compiler/parse_expr.c +++ b/src/compiler/parse_expr.c @@ -30,6 +30,7 @@ bool parse_current_is_expr(ParseContext *c) */ bool parse_range(ParseContext *c, Range *range) { + SourceSpan start = c->span; // Insert zero if missing if (tok_is(c, TOKEN_DOTDOT) || tok_is(c, TOKEN_COLON)) { @@ -62,6 +63,12 @@ bool parse_range(ParseContext *c, Range *range) } // Otherwise we have [1..] or [3:] + if (range->is_len) + { + sema_error_at(extend_span_with_token(start, c->prev_span), "Length-ranges using ':' may not elide the length."); + return false; + } + range->end_from_end = false; range->end = 0; return true; diff --git a/src/version.h b/src/version.h index c699b3b8d..2252f8397 100644 --- a/src/version.h +++ b/src/version.h @@ -1 +1 @@ -#define COMPILER_VERSION "0.4.613" \ No newline at end of file +#define COMPILER_VERSION "0.4.614" \ No newline at end of file diff --git a/test/test_suite/slices/slice_len_error.c3 b/test/test_suite/slices/slice_len_error.c3 new file mode 100644 index 000000000..a40a88097 --- /dev/null +++ b/test/test_suite/slices/slice_len_error.c3 @@ -0,0 +1,21 @@ +int[8][8] a; +fn void main() +{ + a[2..3]; + a[2:1]; + a[..3]; + a[2..]; + a[..]; + a[2:1]; + a[:4]; +} + +fn void test1() +{ + a[:]; // #error: not elide +} + +fn void test2() +{ + a[2:]; // #error: not elide +} \ No newline at end of file diff --git a/test/unit/stdlib/core/bitorder.c3 b/test/unit/stdlib/core/bitorder.c3 index aaca67af2..0c3e64626 100644 --- a/test/unit/stdlib/core/bitorder.c3 +++ b/test/unit/stdlib/core/bitorder.c3 @@ -18,12 +18,12 @@ fn void! test_read() assert(bitorder::read(&bytes, ULongBE) == 0x0102030405060708); assert(bitorder::read(&bytes, ULongLE) == 0x0807060504030201); - assert(bitorder::read(bytes[:], UShortBE) == 0x0102); - assert(bitorder::read(bytes[:], UShortLE) == 0x0201); - assert(bitorder::read(bytes[:], UIntBE) == 0x01020304); - assert(bitorder::read(bytes[:], UIntLE) == 0x04030201); - assert(bitorder::read(bytes[:], ULongBE) == 0x0102030405060708); - assert(bitorder::read(bytes[:], ULongLE) == 0x0807060504030201); + assert(bitorder::read(bytes[..], UShortBE) == 0x0102); + assert(bitorder::read(bytes[..], UShortLE) == 0x0201); + assert(bitorder::read(bytes[..], UIntBE) == 0x01020304); + assert(bitorder::read(bytes[..], UIntLE) == 0x04030201); + assert(bitorder::read(bytes[..], ULongBE) == 0x0102030405060708); + assert(bitorder::read(bytes[..], ULongLE) == 0x0807060504030201); } fn void! test_write() @@ -36,10 +36,10 @@ fn void! test_write() assert(bitorder::read(buf, UShortBE) == x1); uint x2 = bitorder::read(bytes, UIntBE); - bitorder::write(x2, buf[:], UIntBE); + bitorder::write(x2, buf[..], UIntBE); assert(bitorder::read(buf, UIntBE) == x2); ulong x3 = bitorder::read(bytes, ULongBE); - bitorder::write(x3, buf[:], ULongBE); + bitorder::write(x3, buf[..], ULongBE); assert(bitorder::read(buf, ULongBE) == x3); } \ No newline at end of file