Skip to content

Commit

Permalink
Named constants must be of primitive type
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed May 5, 2017
1 parent bd05deb commit 5e51b22
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 14 deletions.
29 changes: 16 additions & 13 deletions src/semantic/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -245,23 +245,26 @@ static void test_script_body( struct semantic* semantic,
struct script* script );

void s_test_constant( struct semantic* semantic, struct constant* constant ) {
// Test expression.
struct expr_test expr;
s_init_expr_test( &expr, true, false );
s_test_expr( semantic, &expr, constant->value_node );
if ( ! expr.undef_erred ) {
if ( constant->value_node->folded ) {
constant->spec = constant->value_node->spec;
constant->value = constant->value_node->value;
constant->has_str = constant->value_node->has_str;
constant->object.resolved = true;
}
else {
s_diag( semantic, DIAG_POS_ERR, &constant->value_node->pos,
"expression not constant" );
s_bail( semantic );
}
if ( expr.undef_erred ) {
return;
}
if ( ! constant->value_node->folded ) {
s_diag( semantic, DIAG_POS_ERR, &constant->value_node->pos,
"expression not constant" );
s_bail( semantic );
}
if ( s_describe_type( &expr.type ) != TYPEDESC_PRIMITIVE ) {
s_diag( semantic, DIAG_POS_ERR, &constant->value_node->pos,
"expression not of primitive type" );
s_bail( semantic );
}
constant->spec = constant->value_node->spec;
constant->value = constant->value_node->value;
constant->has_str = constant->value_node->has_str;
constant->object.resolved = true;
}

void s_test_enumeration( struct semantic* semantic,
Expand Down
2 changes: 1 addition & 1 deletion src/semantic/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -880,7 +880,7 @@ static void test_assign( struct semantic* semantic, struct expr_test* test,
test_operand( semantic, test, &rside, assign->rside );
if ( ! rside.usable ) {
s_diag( semantic, DIAG_POS_ERR, &assign->pos,
"right operand unusable" );
"right operand not a value" );
s_bail( semantic );
}
if ( ! s_instance_of( &lside.type, &rside.type ) ) {
Expand Down

0 comments on commit 5e51b22

Please sign in to comment.