-
Notifications
You must be signed in to change notification settings - Fork 70
Open
Description
I have this struct with an AnyList that I try to read from,
but I cant figure out why the typeid is changing when iterating ofer its members with foreach?
What am I doing wrong here, how can I iterate over the AnyList and use the any-switch?
fn Program Parser.parse_program(&self)
{
AnyList stmts;
stmts.init(self.allocator);
while (self.lexer.has_next()) {
any stmt = self.parse_stmt();
switch(stmt.type) {
case IntStatement:
// THIS CASE IS PRINTED
// parsed int (<struct type:1044591d8, addr:600002564050>)
io::printfn("parsed int (%s)", stmt);
case any: io::printfn("parsed any (%s)", stmt);
}
if (stmt != null) stmts.push(stmt);
self.next_token();
}
foreach(stmt: stmts) {
switch (stmt.type) {
case IntStatement:
io::printfn("IntStatement %s", stmt);
case any:
// THIS CASE IS PRINTED
// found any (<struct type:1044591d8, addr:600002564050>)
io::printfn("found any (%s)", stmt);
}
}
return { stmts };
}Currently {} is required. Theoretically do expr(); while(0); could be allowed
The AnyList expects you to do stuff like:
AnyList list;
list.push(1);
list.push("Hello");If you push an any, then it thinks you mean to pass the any by value, not to expand that any into the AnyList
An AnyList is not a List{any}
shishantbiswas
Metadata
Metadata
Assignees
Labels
No labels