luaur_analysis/functions/
check_require_path.rs1use crate::records::deprecated_api_used::DeprecatedApiUsed;
2use crate::records::type_checker::TypeChecker;
3use crate::type_aliases::type_error_data::TypeErrorData;
4use alloc::string::ToString;
5use luaur_ast::records::ast_expr::AstExpr;
6use luaur_ast::records::ast_expr_index_name::AstExprIndexName;
7use luaur_ast::records::ast_node::AstNode;
8use luaur_ast::rtti::ast_node_as;
9
10pub fn check_require_path(typechecker: &mut TypeChecker, expr: *mut AstExpr) -> bool {
11 let mut good = true;
12 let mut index_expr = unsafe { ast_node_as::<AstExprIndexName>(expr as *mut AstNode) };
13
14 while !index_expr.is_null() {
15 let index_ref = unsafe { &*index_expr };
16 let index_bytes = unsafe { core::ffi::CStr::from_ptr(index_ref.index.value).to_bytes() };
17
18 if index_bytes == b"parent" {
19 typechecker.report_error_location_type_error_data(
20 &index_ref.index_location,
21 TypeErrorData::DeprecatedApiUsed(DeprecatedApiUsed {
22 symbol: "parent".to_string(),
23 use_instead: "Parent".to_string(),
24 }),
25 );
26 good = false;
27 }
28
29 index_expr = unsafe { ast_node_as::<AstExprIndexName>(index_ref.expr as *mut AstNode) };
30 }
31
32 good
33}