Skip to content

Bug: Generic channel functions (send, receive, close) fail type checking #46

@mjm918

Description

@mjm918

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 accept channel<int> and int
  • receive<T>(ch: channel<T>) -> T - should return int for channel<int>
  • close<T>(ch: channel<T>) - should accept channel<int>

Affected Files

  • examples/channels.naml
  • examples/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>.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions