Skip to content

Commit

Permalink
disable redefined parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
LesleyLai committed Feb 1, 2025
1 parent 7a90b9c commit cdfd874
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
7 changes: 3 additions & 4 deletions src/frontend/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -598,10 +598,8 @@ static BlockItem parse_block_item(Parser* parser, Scope* scope)
return result;
}

static Block parse_block(Parser* parser, Scope* parent_scope)
static Block parse_block(Parser* parser, Scope* scope)
{
struct Scope* scope = new_scope(parent_scope, parser->permanent_arena);

struct BlockItemVec items_vec = {};

while (!token_match_or_eof(parser, TOKEN_RIGHT_BRACE)) {
Expand Down Expand Up @@ -681,7 +679,8 @@ static Stmt parse_stmt(Parser* parser, Scope* scope)
case TOKEN_LEFT_BRACE: {
parse_advance(parser);

const Block compound = parse_block(parser, scope);
Scope* block_scope = new_scope(scope, parser->permanent_arena);
const Block compound = parse_block(parser, block_scope);
result = (Stmt){.tag = STMT_COMPOUND, .compound = compound};
break;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
int foo(int a)
{
/* A function's parameter list and its body are in the same scope,
* so redeclaring a here is illegal. */
int a = 5;
return a;
}

int main(void)
{
return foo(3);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{{filename}}:3:7: Error: redefinition of 'a'
3 | int a = 5;
| ^

0 comments on commit cdfd874

Please sign in to comment.