mna / agora

a dynamically typed, garbage collected, embeddable programming language built with Go
https://github.com/mna/agora/wiki
BSD 3-Clause "New" or "Revised" License
324 stars 27 forks source link

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

Open BenLubar opened 10 years ago

BenLubar commented 10 years ago
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

mna commented 10 years ago

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 commented 10 years ago

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.