@@ -303,6 +303,7 @@ def defineVar(self, name, value, scope, is_static=False, expr=None):
303303 name in list (scope .vars .keys ())
304304 and getattr (scope [name ], "is_static" , False )
305305 and type (scope [name ]) != _Undefined
306+ and expr
306307 ):
307308 start = expr ["positions" ]["start" ]
308309 name_length = len (str (name ))
@@ -320,9 +321,32 @@ def defineVar(self, name, value, scope, is_static=False, expr=None):
320321 },
321322 )
322323 else :
324+ value = pyToAdk (value )
325+ if (
326+ self .is_strict
327+ and name in list (scope .vars .keys ())
328+ and type (scope [name ]) != _Undefined
329+ and type (scope [name ]) != type (value )
330+ and expr
331+ ):
332+ start = expr ["positions" ]["start" ]
333+ name_length = len (str (name ))
334+ self .errorhandler .throw (
335+ "Type" ,
336+ f"Cannot reassign a variable with a different type: { name } . Old type: { type (scope [name ])} , New type: { type (value )} ." ,
337+ {
338+ "traceback" : self .traceback ,
339+ "lineno" : start ["line" ],
340+ "marker" : {"start" : start ["col" ], "length" : name_length },
341+ "underline" : {
342+ "start" : start ["col" ] - 2 ,
343+ "end" : start ["col" ] + name_length ,
344+ },
345+ },
346+ )
323347 if getattr (scope [name ], "is_static" , None ) == True :
324348 is_static = True
325- scope [name ] = pyToAdk ( value )
349+ scope [name ] = value
326350 scope [name ].is_static = is_static
327351
328352 def makeFunct (self , expr , parent : Scope , is_macro = False ):
@@ -359,7 +383,7 @@ def x(*args, **kwargs):
359383 # notImplemented(self.errorhandler, "Type Checking", param)
360384 functscope .vars [param ["name" ]] = arg
361385 try :
362- if self . is_strict or param .get ("is_static" , False ):
386+ if param .get ("is_static" , False ):
363387 setattr (functscope .vars [param ["name" ]], "is_static" , True )
364388 # functscope.vars[param["name"]].is_static = True
365389 else :
0 commit comments