I’m having some trouble with running one of the examples in the documentation. I was looking to learn more about channels, so I went to the core:sync/chan documentation, copied the example into a file, added a package line and changed chan_example proc to main. I did an odin run . and it errored. I did it again, and it worked. Sometimes it compiles, sometimes it does not. When it does compile, it functions properly.
Here is the exact source as I have modified it:
package chantest
import "core:fmt"
import "core:sync/chan"
import "core:thread"
// The consumer reads from the channel until it's closed.
// Closing the channel acts as a signal to stop.
consumer :: proc(recv_chan: chan.Chan(int, .Recv)) {
for {
value, ok := chan.recv(recv_chan)
if !ok {
break // More idiomatic than return here
}
fmt.println("[CONSUMER] Received:", value)
}
fmt.println("[CONSUMER] Channel closed, stopping.")
}
// The producer sends `count` number of messages.
producer :: proc(send_chan: chan.Chan(int, .Send), count: int) {
for i in 0 ..< count {
fmt.println("[PRODUCER] Sending:", i)
success := chan.send(send_chan, i)
if !success {
fmt.println("[PRODUCER] Failed to send, channel may be closed.")
return
}
}
// Signal that production is complete by closing the channel.
chan.close(send_chan)
fmt.println("[PRODUCER] Done producing, channel closed.")
}
main :: proc() {
// Create an unbuffered channel for int messages
c, err := chan.create(chan.Chan(int), context.allocator)
assert(err == .None)
defer chan.destroy(c)
// Start the consumer thread
consumer_thread := thread.create_and_start_with_poly_data(chan.as_recv(c), consumer)
defer thread.destroy(consumer_thread)
// Start the producer thread with 5 messages (change count as needed)
producer_thread := thread.create_and_start_with_poly_data2(chan.as_send(c), 5, producer)
defer thread.destroy(producer_thread)
// Wait for both threads to complete
thread.join_multiple(consumer_thread, producer_thread)
}
Here is the acutal error:
/usr/share/odin/core/sync/chan/chan.odin(382:95) Error: 'where' clause evaluated to false:
C.D <= .Both
... (c: $C/Chan($T, $D)) -> (s: Chan(T, .Send)) where C.D <= .Both {
^~~~~~~~~~~^
With the following definitions:
C :: Chan($T=int, $D=1);
T :: int;
D : Direction : 1;
/home/soldrym/odin/chantest/main.odin(46:61) at caller location
Line 46 is this one:
producer_thread := thread.create_and_start_with_poly_data2(chan.as_send(c), 5, producer)
Because it wasn’t consistent, I ran a loop to compile it 80 times (grep for Error to limit screen spam).
soldrym@server:~/odin/chantest$for i in {1..80}; do odin build . 2>&1 | grep Error; done
/usr/share/odin/core/sync/chan/chan.odin(382:95) Error: 'where' clause evaluated to false:
/usr/share/odin/core/sync/chan/chan.odin(382:95) Error: 'where' clause evaluated to false:
/usr/share/odin/core/sync/chan/chan.odin(382:95) Error: 'where' clause evaluated to false:
/usr/share/odin/core/sync/chan/chan.odin(382:95) Error: 'where' clause evaluated to false:
/usr/share/odin/core/sync/chan/chan.odin(382:95) Error: 'where' clause evaluated to false:
/usr/share/odin/core/sync/chan/chan.odin(382:95) Error: 'where' clause evaluated to false:
/usr/share/odin/core/sync/chan/chan.odin(382:95) Error: 'where' clause evaluated to false:
/usr/share/odin/core/sync/chan/chan.odin(382:95) Error: 'where' clause evaluated to false:
/usr/share/odin/core/sync/chan/chan.odin(382:95) Error: 'where' clause evaluated to false:
/usr/share/odin/core/sync/chan/chan.odin(382:95) Error: 'where' clause evaluated to false:
/usr/share/odin/core/sync/chan/chan.odin(382:95) Error: 'where' clause evaluated to false:
The same code compiled successfully 69 times and failed 11. Similar results with dev-2026-07-nightly:819fdc7 and dev-2026-08-nightly:902106f. The number of success/fails are different each time I run the loop, but it’s always a combination of the two.
I’m not sure what to do at this point. Does anyone have any guidance?
Thanks,
-Soldrym