@@ -5,8 +5,8 @@ use std::collections::{HashMap, HashSet};
5
5
6
6
use crate :: {
7
7
ast:: {
8
- self , ConstDef , ConstExpr , ConstExprEnum , EnumDef , Expr , ExprEnum , Mutability , Op ,
9
- ParamDef , Pattern , PatternEnum , Stmt , StmtEnum , StructDef , Type , UnaryOp , Variant ,
8
+ self , Accessor , ConstDef , ConstExpr , ConstExprEnum , EnumDef , Expr , ExprEnum , Mutability ,
9
+ Op , ParamDef , Pattern , PatternEnum , Stmt , StmtEnum , StructDef , Type , UnaryOp , Variant ,
10
10
VariantExprEnum ,
11
11
} ,
12
12
env:: Env ,
@@ -682,43 +682,32 @@ impl UntypedStmt {
682
682
let expr = expr. type_check ( top_level_defs, env, fns, defs) ?;
683
683
Ok ( Stmt :: new ( StmtEnum :: Expr ( expr) , meta) )
684
684
}
685
- ast:: StmtEnum :: VarAssign ( identifier, value) => {
685
+ ast:: StmtEnum :: VarAssign ( identifier, accessors , value) => {
686
686
match env. get ( identifier) {
687
- Some ( ( Some ( ty) , Mutability :: Mutable ) ) => {
688
- let mut value = value. type_check ( top_level_defs, env, fns, defs) ?;
689
- check_type ( & mut value, & ty) ?;
690
- Ok ( Stmt :: new (
691
- StmtEnum :: VarAssign ( identifier. clone ( ) , value) ,
692
- meta,
693
- ) )
694
- }
695
- Some ( ( None , Mutability :: Mutable ) ) => {
696
- // binding does not have a type, must have been caused by a previous error, so
697
- // just ignore the statement here
698
- Err ( vec ! [ None ] )
699
- }
700
- Some ( ( _, Mutability :: Immutable ) ) => Err ( vec ! [ Some ( TypeError (
701
- TypeErrorEnum :: IdentifierNotDeclaredAsMutable ( identifier. clone( ) ) ,
702
- meta,
703
- ) ) ] ) ,
704
- None => Err ( vec ! [ Some ( TypeError (
705
- TypeErrorEnum :: UnknownIdentifier ( identifier. clone( ) ) ,
706
- meta,
707
- ) ) ] ) ,
708
- }
709
- }
710
- ast:: StmtEnum :: ArrayAssign ( identifier, index, value) => {
711
- match env. get ( identifier) {
712
- Some ( ( Some ( array_ty) , Mutability :: Mutable ) ) => {
713
- let elem_ty = expect_array_type ( & array_ty, meta) ?;
714
-
715
- let mut index = index. type_check ( top_level_defs, env, fns, defs) ?;
716
- check_or_constrain_unsigned ( & mut index, UnsignedNumType :: Usize ) ?;
687
+ Some ( ( Some ( mut elem_ty) , Mutability :: Mutable ) ) => {
688
+ let mut typed_accessors = vec ! [ ] ;
689
+ for access in accessors {
690
+ let typed = match access {
691
+ Accessor :: ArrayAccess { index, .. } => {
692
+ let array_ty = elem_ty. clone ( ) ;
693
+ elem_ty = expect_array_type ( & elem_ty, meta) ?;
717
694
695
+ let mut index =
696
+ index. type_check ( top_level_defs, env, fns, defs) ?;
697
+ check_or_constrain_unsigned (
698
+ & mut index,
699
+ UnsignedNumType :: Usize ,
700
+ ) ?;
701
+ println ! ( "Accessor for {array_ty} with {index:?}" ) ;
702
+ Accessor :: ArrayAccess { array_ty, index }
703
+ }
704
+ } ;
705
+ typed_accessors. push ( typed) ;
706
+ }
718
707
let mut value = value. type_check ( top_level_defs, env, fns, defs) ?;
719
708
check_type ( & mut value, & elem_ty) ?;
720
709
Ok ( Stmt :: new (
721
- StmtEnum :: ArrayAssign ( identifier. clone ( ) , index , value) ,
710
+ StmtEnum :: VarAssign ( identifier. clone ( ) , typed_accessors , value) ,
722
711
meta,
723
712
) )
724
713
}
0 commit comments