Skip to content

Commit

Permalink
Private visibility only applies to map objects
Browse files Browse the repository at this point in the history
  • Loading branch information
positively-charged committed Apr 22, 2017
1 parent 259f9cb commit b8618d5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/parse/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,12 @@ void read_dec( struct parse* parse, struct dec* dec ) {
default:
read_visibility( parse, dec );
}
// Private visibility applies only to map objects.
if ( dec->private_visibility && dec->area != DEC_TOP ) {
p_diag( parse, DIAG_POS_ERR, &dec->pos,
"only namespace-level objects can be declared private" );
p_bail( parse );
}
}

void read_enum( struct parse* parse, struct dec* dec ) {
Expand Down Expand Up @@ -1516,7 +1522,6 @@ void add_var( struct parse* parse, struct dec* dec ) {
}
}
else if ( dec->area == DEC_LOCAL || dec->area == DEC_FOR ) {
var->hidden = dec->static_qual;
if ( dec->vars ) {
list_append( dec->vars, var );
}
Expand Down
4 changes: 2 additions & 2 deletions src/semantic/dec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1636,10 +1636,10 @@ bool test_var_finish( struct semantic* semantic, struct var* var ) {
return false;
}
}
// Only map variables can be private, including static variables.
// Only map variables can be private.
if ( var->hidden && var->storage != STORAGE_MAP ) {
s_diag( semantic, DIAG_POS_ERR, &var->object.pos,
"non-map variable declared private" );
"%s variable declared private", t_get_storage_name( var->storage ) );
s_bail( semantic );
}
if ( var->storage == STORAGE_WORLD || var->storage == STORAGE_GLOBAL ) {
Expand Down

0 comments on commit b8618d5

Please sign in to comment.