@@ -137,7 +137,8 @@ impl Compiler {
137
137
array_index_assign : ArrayIndexAssign ,
138
138
) -> * mut gcc_jit_rvalue {
139
139
let ( lvalue, _) = self . access_identifier_values ( Rc :: clone ( & scope) , array_index_assign. from_package ) ;
140
- let array_index_lvalue = self . array_dimension_as_lvalue ( Rc :: clone ( & scope) , lvalue, array_index_assign. dimensions ) ;
140
+ let array_index_lvalue =
141
+ self . array_dimension_as_lvalue ( Rc :: clone ( & scope) , lvalue, array_index_assign. dimensions ) ;
141
142
142
143
let block_func = self . block_func_ref . lock ( ) . unwrap ( ) ;
143
144
if let Some ( block) = block_func. block {
@@ -170,11 +171,12 @@ impl Compiler {
170
171
}
171
172
_ => {
172
173
let rvalue_type = unsafe { gcc_jit_rvalue_get_type ( gcc_jit_lvalue_as_rvalue ( array_index_lvalue) ) } ;
174
+ let expr = array_index_assign. expr . clone ( ) ;
173
175
return self . safe_assign_lvalue (
174
176
Rc :: clone ( & scope) ,
175
177
array_index_lvalue,
176
178
rvalue_type,
177
- array_index_assign . expr . clone ( ) ,
179
+ expr,
178
180
array_index_assign. loc ,
179
181
) ;
180
182
}
@@ -190,12 +192,19 @@ impl Compiler {
190
192
variable : * mut gcc_jit_lvalue ,
191
193
dimensions : Vec < Expression > ,
192
194
) -> * mut gcc_jit_lvalue {
195
+ if dimensions. len ( ) == 0 {
196
+ compiler_error ! ( "You are trying to access an array item lvalue with empty dimension." )
197
+ }
198
+
193
199
let mut result: * mut gcc_jit_lvalue = variable;
194
200
195
201
for dim in dimensions {
196
202
if let Expression :: Array ( index_expr) = dim {
197
- if let Expression :: Array ( value) = index_expr. elements [ 0 ] . clone ( ) {
198
- let idx = self . compile_expression ( Rc :: clone ( & scope) , value. elements [ 0 ] . clone ( ) ) ;
203
+ if let Expression :: Literal ( Literal :: Integer ( integer_literal) ) = index_expr. elements [ 0 ] . clone ( ) {
204
+ let idx = self . compile_expression (
205
+ Rc :: clone ( & scope) ,
206
+ Expression :: Literal ( Literal :: Integer ( integer_literal) ) ,
207
+ ) ;
199
208
200
209
let lvalue = unsafe {
201
210
gcc_jit_context_new_array_access (
@@ -207,10 +216,16 @@ impl Compiler {
207
216
} ;
208
217
209
218
result = lvalue;
219
+ } else {
220
+ compiler_error ! ( "Unable to access array lvalue through a non-integer literal." )
210
221
}
211
222
}
212
223
}
213
224
225
+ if result == variable {
226
+ compiler_error ! ( "Unexpected behavior when trying to compile array_dimension_as_lvalue." )
227
+ }
228
+
214
229
result
215
230
}
216
231
@@ -304,6 +319,7 @@ impl Compiler {
304
319
compiler_error ! ( "Incorrect usage of the assignment. Assignments must be performed inside a valid block." ) ;
305
320
}
306
321
}
322
+
307
323
fn compile_assignment ( & mut self , scope : ScopeRef , assignment : Assignment ) -> * mut gcc_jit_rvalue {
308
324
let ( lvalue, rvalue) = self . access_identifier_values ( Rc :: clone ( & scope) , assignment. identifier ) ;
309
325
let rvalue_type = unsafe { gcc_jit_rvalue_get_type ( rvalue) } ;
@@ -521,10 +537,18 @@ impl Compiler {
521
537
} ,
522
538
Literal :: Float ( float_literal) => match float_literal {
523
539
FloatLiteral :: Float ( value) => unsafe {
524
- gcc_jit_context_new_rvalue_from_double ( self . context , Compiler :: float_type ( self . context ) , value as f64 )
540
+ gcc_jit_context_new_rvalue_from_double (
541
+ self . context ,
542
+ Compiler :: float_type ( self . context ) ,
543
+ value as f64 ,
544
+ )
525
545
} ,
526
546
FloatLiteral :: Double ( value) => unsafe {
527
- gcc_jit_context_new_rvalue_from_double ( self . context , Compiler :: double_type ( self . context ) , value as f64 )
547
+ gcc_jit_context_new_rvalue_from_double (
548
+ self . context ,
549
+ Compiler :: double_type ( self . context ) ,
550
+ value as f64 ,
551
+ )
528
552
} ,
529
553
} ,
530
554
Literal :: Bool ( bool_literal) => {
0 commit comments