Fix missing check on foreach indexing.

This commit is contained in:
Christoffer Lerno
2022-11-14 15:05:01 +01:00
parent 5ff726d8d1
commit c093f16fd0
3 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,27 @@
import std::io;
struct Foo
{
int[3] elements;
}
fn int Foo.at(Foo *vector, float index) @operator([])
{
return 1;
}
fn int Foo.len(Foo *vector) @operator(len)
{
return 3;
}
fn void main()
{
Foo f;
io::printfln("%s", f[12.2]);
foreach (int i, value : f) // #error: Only integer
{
io::printfln("v[%s] = %s", i, value);
}
}

View File

@@ -0,0 +1,27 @@
import std::io;
struct Foo
{
int[3] elements;
}
fn int Foo.at(Foo *vector, float index) @operator([])
{
return 1;
}
fn int Foo.len(Foo *vector) @operator(len)
{
return 3;
}
fn void main()
{
Foo f;
io::printfln("%s", f[12.2]);
foreach (int i, value : f) // #error: Only integer
{
io::printfln("v[%s] = %s", i, value);
}
}