ceu-lang / ceu

The Programming Language Céu

Home Page:http://www.ceu-lang.org/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error when using anonymous identifier in loop

rodrimc opened this issue · comments

The following loop doesn't compile:

var uint x = 10; //it works with 'int' datatype
loop _ in [0 -> x] do
end

escape 0;

Error: invalid control variable : types mismatch : "int" <= "uint"

Version: 7beb2ad

It also works if one removes the anonymous identifier:

var uint x = 10;
var uint i;
loop i in [0 -> x] do
end

escape 0;

Here is what happens:

  1. In an early phase (adjs.lua:387), the Céu compiler detects the _ and replaces it with a hardwired int.
  2. Type compatibility is checked much later (stmts.lua:506).
    Alas, I'm not familiar enough with Céu's compiler internals or the Lua language to know whether adjs.lua could leave a dummy, or supply a fake type that will get overwritten later.

Also, I'm not familiar at all with type inference in this compiler in the presence of literals. What type of integer should be introduced in the following cases?

  • [ 0 -> 10],1 (I hope for the best: u8)
  • [ 0 -> 256],1 (u16?)
  • [ -10 <- 10 ],1 (s8?)
  • native x,y,s; loop _ in [ x -> y ], s do ... ??

I believe that in the latter case, Céu doesn't know anything about the actual types.

  • Should that be an error?
  • A warning ("unknown types, defaulting to int at your own risk")?
  • Use GCC's typeof(x) extension? (That would not work with native/const literals in C, only variables and derived expressions.)