mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Fix missing check on foreach indexing.
This commit is contained in:
27
test/test_suite/statements/foreach_wrong_index.c3
Normal file
27
test/test_suite/statements/foreach_wrong_index.c3
Normal 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);
|
||||
}
|
||||
}
|
||||
27
test/test_suite2/statements/foreach_wrong_index.c3
Normal file
27
test/test_suite2/statements/foreach_wrong_index.c3
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user