8000 closures can't be assigned to local variables · Issue #152 · zetzit/zz · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on Jun 17, 2022. It is now read-only.
This repository was archived by the owner on Jun 17, 2022. It is now read-only.

closures can't be assigned to local variables #152

Open

Description

@sternenseemann

Taken from the README with fixed syntax:

closure rand_t() -> int;

fn secure_random() -> int {
    return 42;
}

fn main() {
    rand_t rand = secure_random;
}

Compiling fails:

[ERROR] incompatible types ::zztest::main::rand_t and ::zztest::main::secure_random
 --> /home/lukas/src/misc/zztest/src/main.zz:8:5
  |
8 |     rand_t rand = secure_random;␊
  |     ^-------------------------^
  |
  = this expression is unprovable over incompatible types

 --> /home/lukas/src/misc/zztest/src/main.zz:8:5
  |
8 |     rand_t rand = secure_random;␊
  |     ^-------------------------^
  |
  = rand := ::zztest::main::rand_t Uninitialized

 --> /home/lukas/src/misc/zztest/src/main.zz:3:1
  |
3 | fn secure_random() -> int {␊
  | ...
6 | fn main() -> int {␊
  | ^
  |
  = ::zztest::main::secure_random := ::zztest::main::secure_random Uninitialized

Activity

  1. aep commented on Jan 26, 2021

    @aep
    Collaborator

    ah yes, closures can't be assigned to local variables. i dont know why, this looks like a bug.

  2. changed the title [-]closures don't work as documented[/-] [+]closures can't be assigned to local variables[/+] on Jan 26, 2021
  3. added
    bugSomething isn't working
    on Jan 26, 2021
  4. aep commented on Jan 26, 2021

    @aep
    Collaborator

    oh i remember why. fixing this is hard because closures are emitted as structures for capture context.
    this is a corner case where there's no special assignment case in symbolic, its just passed as literal = into C, and using = for structs is not legal in C. We'd either need yet another special case or finally some more generic way to assignment.

  5. jacereda commented on May 4, 2021

    @jacereda

    C should handle = for structs AFAIK...

    
    struct foo { void * p; int i; };
    
    struct foo test() {
      struct foo a = {0,1};
      struct foo b;
      b = a;
      return b;
    }
    
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0