diff --git a/nac3core/src/toplevel/type_annotation.rs b/nac3core/src/toplevel/type_annotation.rs index f8b16f8..e3b2911 100644 --- a/nac3core/src/toplevel/type_annotation.rs +++ b/nac3core/src/toplevel/type_annotation.rs @@ -101,7 +101,13 @@ pub fn parse_ast_to_type_annotation_kinds( Ok(TypeAnnotation::CustomClass { id: PrimDef::Exception.id(), params: Vec::default() }) } else if let Ok(obj_id) = resolver.get_identifier_def(*id) { let type_vars = { - let def_read = top_level_defs[obj_id.0].try_read(); + let Some(top_level_def) = top_level_defs.get(obj_id.0) else { + return Err(HashSet::from([format!( + "NameError: name '{id}' is not defined (at {})", + expr.location + )])); + }; + let def_read = top_level_def.try_read(); if let Some(def_read) = def_read { if let TopLevelDef::Class { type_vars, .. } = &*def_read { type_vars.clone() @@ -156,12 +162,17 @@ pub fn parse_ast_to_type_annotation_kinds( } let obj_id = resolver.get_identifier_def(*id)?; let type_vars = { - let def_read = top_level_defs[obj_id.0].try_read(); + let Some(top_level_def) = top_level_defs.get(obj_id.0) else { + return Err(HashSet::from([format!( + "NameError: name '{id}' is not defined (at {})", + expr.location + )])); + }; + let def_read = top_level_def.try_read(); if let Some(def_read) = def_read { let TopLevelDef::Class { type_vars, .. } = &*def_read else { unreachable!("must be class here") }; - type_vars.clone() } else { locked.get(&obj_id).unwrap().clone()