luaur_ast/methods/
parser_report_l_value_error.rs1use crate::records::ast_expr::AstExpr;
2use crate::records::ast_expr_error::AstExprError;
3use crate::records::ast_expr_local::AstExprLocal;
4use crate::records::parser::Parser;
5
6impl Parser {
7 pub fn report_l_value_error(&mut self, expr: *mut AstExpr) -> *mut AstExprError {
8 if luaur_common::FFlag::LuauConst2.get() {
9 let local_expr = unsafe {
10 crate::rtti::ast_node_as::<AstExprLocal>(
11 expr as *mut crate::records::ast_node::AstNode,
12 )
13 };
14 if !local_expr.is_null() {
15 let local = unsafe { &*local_expr };
16 if !local.local.is_null() && unsafe { (*local.local).is_const } {
17 let location = unsafe { (*expr).base.location };
18 let expressions = self.copy_initializer_list_t(&[expr]);
19 let name = unsafe { (*local.local).name.value };
20 return self.report_expr_error(
21 location,
22 expressions,
23 format_args!(
24 "Variable '{}' is constant and may not be reassigned",
25 unsafe { core::ffi::CStr::from_ptr(name).to_string_lossy() }
26 ),
27 );
28 }
29 }
30 }
31
32 let location = unsafe { (*expr).base.location };
33 let expressions = self.copy_initializer_list_t(&[expr]);
34 self.report_expr_error(
35 location,
36 expressions,
37 format_args!("Assigned expression must be a variable or a field"),
38 )
39 }
40}