Eliding length for ":"-ranges is no longer allowed.

This commit is contained in:
Christoffer Lerno
2023-08-18 22:25:51 +02:00
parent 17f69d8da8
commit d5aebb434c
6 changed files with 39 additions and 10 deletions

View File

@@ -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?;

View File

@@ -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.

View File

@@ -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;

View File

@@ -1 +1 @@
#define COMPILER_VERSION "0.4.613"
#define COMPILER_VERSION "0.4.614"

View File

@@ -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
}

View File

@@ -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);
}