@@ -954,10 +954,10 @@ impl SymbolTableBuilder {
954
954
// Some checks:
955
955
let containing = table. symbols . contains_key ( name) ;
956
956
if containing {
957
+ let symbol = table. symbols . get ( name) . unwrap ( ) ;
957
958
// Role already set..
958
959
match role {
959
960
SymbolUsage :: Global => {
960
- let symbol = table. symbols . get ( name) . unwrap ( ) ;
961
961
if let SymbolScope :: Global = symbol. scope {
962
962
// Ok
963
963
} else {
@@ -968,10 +968,33 @@ impl SymbolTableBuilder {
968
968
}
969
969
}
970
970
SymbolUsage :: Nonlocal => {
971
- return Err ( SymbolTableError {
972
- error : format ! ( "name '{}' is used prior to nonlocal declaration" , name) ,
973
- location,
974
- } )
971
+ if symbol. is_parameter {
972
+ return Err ( SymbolTableError {
973
+ error : format ! ( "name '{}' is parameter and nonlocal" , name) ,
974
+ location,
975
+ } ) ;
976
+ }
977
+ if symbol. is_referenced {
978
+ return Err ( SymbolTableError {
979
+ error : format ! ( "name '{}' is used prior to nonlocal declaration" , name) ,
980
+ location,
981
+ } ) ;
982
+ }
983
+ if symbol. is_annotated {
984
+ return Err ( SymbolTableError {
985
+ error : format ! ( "annotated name '{}' can't be nonlocal" , name) ,
986
+ location,
987
+ } ) ;
988
+ }
989
+ if symbol. is_assigned {
990
+ return Err ( SymbolTableError {
991
+ error : format ! (
992
+ "name '{}' is assigned to before nonlocal declaration" ,
993
+ name
994
+ ) ,
995
+ location,
996
+ } ) ;
997
+ }
975
998
}
976
999
_ => {
977
1000
// Ok?
0 commit comments