berry-lang / berry

A ultra-lightweight embedded scripting language optimized for microcontrollers.
https://berry-lang.github.io
MIT License
782 stars 95 forks source link

Using uninitialized variables #414

Closed yuppox closed 2 months ago

yuppox commented 2 months ago

Hi.

Is this expected behavior? If I append an uninitialized variable to print, it shows a random value. If I try to print the variable on its own, it gives me an error:

> print("hello")
hello
> print("hello "..x)
hello 9223372036854775807
> print(x)
syntax_error: stdin:1: 'x' undeclared (first use in this function)

It seems like the system should throw an error for the appended print, too.

s-hadinger commented 2 months ago

Indeed, that's an unwanted side effect.

s-hadinger commented 2 months ago

Wow, this fix made me find a hard to find bug in my Matter code. Thanks !

s-hadinger commented 2 months ago

Fixed in https://github.com/berry-lang/berry/pull/415 (waiting for merge)