lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]




On Friday, April 10, 2015, Dibyendu Majumdar <mobile@majumdar.org.uk> wrote:
Hi,

While working on the core API the realization dawned that up-values
can subvert static typing of local variables :-(

> function x() local i: integer; return function(j) i = j; end; end
> f=x()
> f(5)
> f('hello')

Haven't thought yet how to fix this:
a) Probably easiest to disallow referencing typed values in up-values
b) Alternatively up-values need to be typed ... not sure if that is
possible to enforce at compile time

Regards
Dibyendu


I don't understand. Is it a design problem or implementation issue? As a design question, it seems straightforward. The last line should error and that seems unambiguous to me. 

local i: integer --declaration. 
return function(j) --argument j is declared as a non-typed value.  
  i = j --at runtime, you'll need to check if j is an integer or not because i is a reference to a static type. 
...

Anything other than that would be confusing to me, r am I missing something?

-Andrew