Skip to main content

luaur_analysis/functions/
check_require_path_dcr.rs

1use crate::records::constraint_solver::ConstraintSolver;
2use crate::records::deprecated_api_used::DeprecatedApiUsed;
3use crate::type_aliases::type_error_data::TypeErrorData;
4use core::ptr::NonNull;
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_dcr(mut solver: NonNull<ConstraintSolver>, 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            let deprecated = DeprecatedApiUsed {
20                symbol: "parent".to_string(),
21                use_instead: "Parent".to_string(),
22            };
23            let data = TypeErrorData::DeprecatedApiUsed(deprecated);
24            unsafe {
25                solver
26                    .as_mut()
27                    .report_error_type_error_data_location(data, &index_ref.index_location);
28            }
29            good = false;
30        }
31
32        index_expr = unsafe { ast_node_as::<AstExprIndexName>(index_ref.expr as *mut AstNode) };
33    }
34
35    good
36}