Files
mgmt/lang/interpret_test/TestAstFunc2/test-monomorphic-class-arg.txtar
James Shubin cf7e73bbf6 lang: Add a for loop statement for iterating over a list
This adds a for statement which is used to iterate over a list with a
body of statements. This is an important data transformation tool which
should be used sparingly, but is important to have.

An import statement inside of a for loop is not currently supported. We
have a simple hack to detect the obvious cases, but more deeply nested
scenarios probably won't be caught, and you'll get an obscure error
message if you try to do this.

This was incredibly challenging to get right, and it's all thanks to Sam
for his brilliance.

Co-authored-by: Samuel Gélineau <gelisam@gmail.com>
2025-03-08 17:45:29 -05:00

16 lines
458 B
Plaintext

-- main.mcl --
# $id could theoretically have type func(int) int or func(str) str, but it
# can't be both because it is bound to a class parameter, which must have a
# single type.
class use_polymorphically($id) {
test "test1" {
int8 => $id(42),
}
test "test2" {
anotherstr => $id("hello"),
}
}
include use_polymorphically(func($x) {$x})
-- OUTPUT --
# err: errUnify: unify error with: topLevel(singleton(func(x) { var(x) })): type error: str != int