-
Notifications
You must be signed in to change notification settings - Fork 0
Closed
Description
Description
The generic channel functions send<T>, receive<T>, and close<T> in std::threads fail type checking with confusing error messages. The typechecker is not properly resolving the generic type parameter T from the channel<T> type.
Error Messages
× type mismatch: expected int, found Spur(1) at 11:10
╭─[examples/channels.naml:11:10]
10 │ println("Sending values...");
11 │ send(ch, 10);
· ─┬
· ╰── expected int
The error "expected int, found Spur(1)" is confusing - Spur(1) appears to be an internal type representation leaking into user-facing error messages.
Reproduction
use std::threads::*;
fn main() {
var ch: channel<int> = open_channel(5);
send(ch, 10); // Error: type mismatch
var v: int = receive(ch); // Error: type mismatch
close(ch); // Error: type mismatch
}
Expected Behavior
The generic functions should correctly infer T from the channel<T> argument:
send<T>(ch: channel<T>, value: T)- should acceptchannel<int>andintreceive<T>(ch: channel<T>) -> T- should returnintforchannel<int>close<T>(ch: channel<T>)- should acceptchannel<int>
Affected Files
examples/channels.namlexamples/spawn.naml
Technical Notes
The functions are defined as generic in namlc/src/typechecker/mod.rs:
StdModuleFn::generic("send", vec!["T"], vec![("ch", channel_t.clone()), ("value", Type::Generic("T".into()))], Type::Int),
StdModuleFn::generic("receive", vec!["T"], vec![("ch", channel_t.clone())], Type::Generic("T".into())),
StdModuleFn::generic("close", vec!["T"], vec![("ch", channel_t)], Type::Unit),The issue appears to be in how generic type parameters are resolved when the first argument is a generic container type like channel<T>.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels