Skip to content

Commit

Permalink
Fix: sure operator broke from some previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed May 12, 2017
1 parent 5e2bbfb commit 95c8305
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/semantic/expr.c
Original file line number Diff line number Diff line change
Expand Up @@ -2332,7 +2332,8 @@ static void test_sure( struct semantic* semantic, struct expr_test* test,
}
else {
struct type_snapshot snapshot;
s_take_type_snapshot( &operand.type, &snapshot );
s_take_fine_type_snapshot( &operand.type, &snapshot,
operand.type.ref->nullable );
sure->ref = snapshot.ref;
if ( sure->ref->nullable ) {
sure->ref->nullable = false;
Expand Down
2 changes: 2 additions & 0 deletions src/semantic/phase.h
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,8 @@ bool s_is_scalar( struct type_info* type );
bool s_is_str_value_type( struct type_info* type );
void s_take_type_snapshot( struct type_info* type,
struct type_snapshot* snapshot );
void s_take_fine_type_snapshot( struct type_info* type,
struct type_snapshot* snapshot, bool force_dup_ref );
bool s_is_onedim_int_array( struct type_info* type );
bool s_is_int_value( struct type_info* type );
bool s_is_str_value( struct type_info* type );
Expand Down
18 changes: 13 additions & 5 deletions src/semantic/type.c
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,21 @@ enum subscript_result s_subscript_array_ref( struct semantic* semantic,
}
}

// NOTE: This function only makes sure that the data referenced by @type will
// be valid throughout compilation; it does not create new instances of the
// data unless it is necessary. Be careful when editing the data returned by
// this function because multiple objects might be sharing the same instance.
// Maybe avoid this whole situation and just allocate new instances every time?
void s_take_type_snapshot( struct type_info* type,
struct type_snapshot* snapshot ) {
if ( type->ref && type->ref->implicit ) {
snapshot->ref = dup_ref( type->ref );
}
else {
snapshot->ref = type->ref;
s_take_fine_type_snapshot( type, snapshot, false );
}

void s_take_fine_type_snapshot( struct type_info* type,
struct type_snapshot* snapshot, bool force_dup_ref ) {
snapshot->ref = type->ref;
if ( snapshot->ref && ( snapshot->ref->implicit || force_dup_ref ) ) {
snapshot->ref = dup_ref( snapshot->ref );
}
snapshot->structure = type->structure;
snapshot->enumeration = type->enumeration;
Expand Down

0 comments on commit 95c8305

Please sign in to comment.