agora icon indicating copy to clipboard operation
agora copied to clipboard

y := x = x + 1 is accepted and does strange things.

Open BenLubar opened this issue 10 years ago • 2 comments

fmt := import("fmt")

x := 0
fmt.Println(x) // A
y := x = x + 1
fmt.Println(x, y)

This program prints:

0
1 2

Comment out line A and it prints:

runtime error: index out of range

In my opinion, this code should not compile.

I ran these snippets using agora run -R

agora version: 8701d7f97e0b78d606b0df6daf531e9ee602a69e Go version: go version devel +84975e4930dd Tue Sep 17 18:06:58 2013 -0700 linux/amd64

BenLubar avatar Sep 18 '13 20:09 BenLubar

Haha, I'm so not surprised :) Thanks for submitting the issue, I'm sure the compiler allows all kind of messy things right now. I'll fix this for the next release.

mna avatar Sep 18 '13 20:09 mna

Actually this will be adressed in v0.4, when I rewrite the compiler. There's not much sense in fixing it right now as there are many other problems with the current compiler, and I will rewrite it pretty much from scratch down the road.

mna avatar Sep 28 '13 00:09 mna