File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -26,9 +26,6 @@ int getchar()
2626}
2727#endif
2828
29- // Internal buffer used by printf
30- char * __buffer [32 ];
31-
3229int printf (char * format , ...)
3330{
3431 unsigned int ch_written = 0 ;
Original file line number Diff line number Diff line change @@ -93,6 +93,14 @@ impl Env
9393 offset
9494 }
9595
96+ /// Check if a local with this name is already defined
97+ fn local_defined ( & self , name : & str ) -> bool
98+ {
99+ let num_scopes = self . scopes . len ( ) ;
100+ let top_scope = & self . scopes [ num_scopes - 1 ] ;
101+ top_scope. decls . get ( name) . is_some ( )
102+ }
103+
96104 /// Define a new local variable in the topmost scope
97105 fn define_local ( & mut self , name : & str , var_type : Type )
98106 {
@@ -330,6 +338,13 @@ impl Stmt
330338
331339 // Local variable declaration
332340 Stmt :: VarDecl { var_type, var_name, init_expr } => {
341+ if env. local_defined ( var_name) {
342+ return ParseError :: msg_only ( & format ! (
343+ "local with name \" {}\" already exists" ,
344+ var_name
345+ ) ) ;
346+ }
347+
333348 env. define_local ( var_name, var_type. clone ( ) ) ;
334349
335350 let decl = env. lookup ( var_name) . unwrap ( ) ;
You can’t perform that action at this time.
0 commit comments