Skip to content

Commit f10444e

Browse files
committed
Require ; after assert statement
It's just consistent. And update the grammar.
1 parent a812dcc commit f10444e

10 files changed

+36
-39
lines changed

regression-tests/mixed-bounds-safety-with-assert-2.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ main: () -> int = {
99

1010
add_42_to_subrange: (inout rng:_, start:int, end:int)
1111
= {
12-
assert<Bounds>( 0 <= start )
13-
assert<Bounds>( end <= rng.ssize() )
12+
assert<Bounds>( 0 <= start );
13+
assert<Bounds>( end <= rng.ssize() );
1414

1515
count := 0;
1616
for rng

regression-tests/mixed-bounds-safety-with-assert.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ main: () -> int = {
77
}
88

99
print_subrange: (rng:_, start:int, end:int) = {
10-
assert<Bounds>( 0 <= start )
11-
assert<Bounds>( end <= rng.ssize() )
10+
assert<Bounds>( 0 <= start );
11+
assert<Bounds>( end <= rng.ssize() );
1212

1313
count := 0;
1414
for rng
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include <chrono>
22
using namespace std::chrono_literals;
33
main: () = {
4-
assert( 10 as i32 == 10 )
5-
assert( 10LL as i32 == 10 )
6-
assert( 10s as std::chrono::seconds == 10s )
4+
assert( 10 as i32 == 10 );
5+
assert( 10LL as i32 == 10 );
6+
assert( 10s as std::chrono::seconds == 10s );
77
}

regression-tests/pure2-bugfix-for-assign-expression-list.cpp2

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@ main: () = {
22
vec: type == std::vector<int>;
33
v: vec = (0);
44
v = ();
5-
assert( v == :vec = () )
5+
assert( v == :vec = () );
66
v = (1);
7-
assert( v == :vec = (1) )
7+
assert( v == :vec = (1) );
88
v = (2, 3);
9-
assert( v == :vec = (2, 3) )
9+
assert( v == :vec = (2, 3) );
1010
}

regression-tests/pure2-bugfix-for-non-local-initialization.cpp2

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ t: @struct type = {
33
this: std::integral_constant<u, :u = (17, 29)>;
44
}
55
main: () = {
6-
assert<Testing>( t::value[0] == 17 )
7-
assert<Testing>( t::value[1] == 29 )
6+
assert<Testing>( t::value[0] == 17 );
7+
assert<Testing>( t::value[1] == 29 );
88
}
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
arithmetic: <T> concept = std::integral<T> || std::floating_point<T>;
22
main: () = {
3-
assert<Testing>( arithmetic<i32> )
4-
assert<Testing>( arithmetic<float> )
3+
assert<Testing>( arithmetic<i32> );
4+
assert<Testing>( arithmetic<float> );
55
}

regression-tests/pure2-print.cpp2

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ outer: @print type = {
4646
else if !m.empty() { b(); }
4747
else { c(); }
4848

49-
assert( true )
49+
assert( true );
5050

5151
return :() -> std::string = (s + m[0])$; ();
5252
}

source/parse.h

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7001,9 +7001,12 @@ class parser
70017001
//G jump-statement
70027002
//G iteration-statement
70037003
//G compound-statement
7004-
//G contract
7004+
//G contract-statement
70057005
//G declaration
70067006
//G expression-statement
7007+
//G
7008+
//G contract-statement
7009+
//G contract ';'
70077010
//
70087011
//GTODO try-block
70097012
//G
@@ -7089,6 +7092,11 @@ class parser
70897092
error("only 'assert' contracts are allowed at statement scope");
70907093
return {};
70917094
}
7095+
if (curr().type() != lexeme::Semicolon) {
7096+
error("missing ';' after contract-statement");
7097+
return {};
7098+
}
7099+
next();
70927100
n->statement = std::move(s);
70937101
assert (n->is_contract());
70947102
return n;
@@ -7467,8 +7475,8 @@ class parser
74677475

74687476

74697477
//G contract:
7470-
//G contract-kind contract-group? ':' logical-or-expression ']' ']'
7471-
//G contract-kind contract-group? ':' logical-or-expression ',' string-literal ']' ']'
7478+
//G contract-kind contract-group? ':' '(' logical-or-expression ')'
7479+
//G contract-kind contract-group? ':' '(' logical-or-expression ',' string-literal ')'
74727480
//G
74737481
//G contract-group:
74747482
//G '<' id-expression '>'
@@ -7540,17 +7548,6 @@ class parser
75407548
}
75417549
next();
75427550

7543-
// Allow optional ';' after an assert, which is really an empty
7544-
// statement (I'm not putting it in the grammar) and so this is
7545-
// to skip the "empty statement" check and error
7546-
if (
7547-
*n->kind == "assert"
7548-
&& curr().type() == lexeme::Semicolon
7549-
)
7550-
{
7551-
next();
7552-
}
7553-
75547551
return n;
75557552
}
75567553

source/reflect.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ type_id: @polymorphic_base @copyable type =
156156
= {
157157
compiler_services = s;
158158
n = n_;
159-
assert( n, "a meta::type_id must point to a valid type_id_node, not null" )
159+
assert( n, "a meta::type_id must point to a valid type_id_node, not null" );
160160
}
161161
162162
is_wildcard : (this) -> bool = n.is_wildcard();

source/reflect.h2

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ compiler_services: @polymorphic_base @copyable type =
107107
tokens := generated_lexers.back()&;
108108
tokens*.lex( lines*, true );
109109

110-
assert( std::ssize(tokens* .get_map()) == 1 )
110+
assert( std::ssize(tokens* .get_map()) == 1 );
111111

112112
// Now parse this single declaration from
113113
// the lexed tokens
@@ -168,7 +168,7 @@ type_id: @polymorphic_base @copyable type =
168168
= {
169169
compiler_services = s;
170170
n = n_;
171-
assert( n, "a meta::type_id must point to a valid type_id_node, not null" )
171+
assert( n, "a meta::type_id must point to a valid type_id_node, not null" );
172172
}
173173

174174
is_wildcard : (this) -> bool = n*.is_wildcard();
@@ -204,7 +204,7 @@ declaration_base: @polymorphic_base @copyable type =
204204
= {
205205
compiler_services = s;
206206
n = n_;
207-
assert( n, "a meta::declaration must point to a valid declaration_node, not null" )
207+
assert( n, "a meta::declaration must point to a valid declaration_node, not null" );
208208
}
209209

210210
position: (override this) -> source_position = n*.position();
@@ -285,7 +285,7 @@ declaration: @polymorphic_base @copyable type =
285285
pre<Type>( parent_is_type() ) // this precondition should be sufficient ...
286286
= {
287287
test := n*.type_member_mark_for_removal();
288-
assert( test ) // ... to ensure this assert is true
288+
assert( test ); // ... to ensure this assert is true
289289
}
290290
}
291291

@@ -304,7 +304,7 @@ function_declaration: @copyable type =
304304
) =
305305
{
306306
declaration = (n_, s);
307-
assert( n*.is_function() )
307+
assert( n*.is_function() );
308308
}
309309

310310
index_of_parameter_named : (this, s: std::string_view) -> int = n*.index_of_parameter_named(s);
@@ -361,7 +361,7 @@ object_declaration: @copyable type =
361361
) =
362362
{
363363
declaration = (n_, s);
364-
assert( n*.is_object() )
364+
assert( n*.is_object() );
365365
}
366366

367367
is_const : (this) -> bool = n*.is_const();
@@ -397,7 +397,7 @@ type_declaration: @copyable type =
397397
) =
398398
{
399399
declaration = (n_, s);
400-
assert( n*.is_type() )
400+
assert( n*.is_type() );
401401
}
402402

403403
reserve_names: (this, name: std::string_view, forward etc...) =
@@ -510,7 +510,7 @@ alias_declaration: @copyable type =
510510
) =
511511
{
512512
declaration = (n_, s);
513-
assert( n*.is_alias() )
513+
assert( n*.is_alias() );
514514
}
515515
}
516516

@@ -1239,7 +1239,7 @@ apply_metafunctions: (
12391239
)
12401240
-> bool
12411241
= {
1242-
assert( n.is_type() )
1242+
assert( n.is_type() );
12431243

12441244
// Check for _names reserved for the metafunction implementation
12451245
for rtype.get_members()

0 commit comments

Comments
 (0)