Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when using anonymous identifier in loop #120

Open
rodrimc opened this issue Apr 11, 2018 · 3 comments
Open

Error when using anonymous identifier in loop #120

rodrimc opened this issue Apr 11, 2018 · 3 comments
Labels

Comments

@rodrimc
Copy link
Contributor

rodrimc commented Apr 11, 2018

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

@rodrimc
Copy link
Contributor Author

rodrimc commented Apr 11, 2018

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;

@fsantanna fsantanna added the bug label Apr 12, 2018
@fsantanna
Copy link
Collaborator

Thanks.

@jhoehle
Copy link
Contributor

jhoehle commented Feb 5, 2019

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.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants