d5 / tengo

A fast script language for Go

Home Page:https://tengolang.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Runtime panic on self assignment

beoran opened this issue · comments

The following Tengo script panics at run time:

a := a.foo

This likely because the compiler wrongly considers a to be defined after the := . A should only be considered defined in the next statement.

Right, this is a problem, but I'm not sure your solution would work. It would break recursive functions.

For a func block, an exception can be made to the rule I propose that the variable is defined inside there.

Edit: Or, the semantics could stay the same as now, but then a.foo should return undefined in stead of panicking.

Thanks for the fix!