Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't execute __temp_51[0] at /tmp/example.cr:12:22: __temp_51 has no type #2241

Closed
DougEverly opened this issue Feb 28, 2016 · 1 comment
Closed

Comments

@DougEverly
Copy link
Contributor

crystal run /tmp/example.cr 
can't execute `__temp_51[0]` at /tmp/example.cr:12:22: `__temp_51` has no type
enum Control
  Start
  Stop
end

items = Channel(String).new(10)
control = Channel(Control).new(10)

spawn do
  begin
    loop do
      index, value = Channel(String|Control).select(items, control)
      case value
      when String
        puts value
      when Control
        puts "control item"
      else
        puts "else"
      end
    end
  rescue e : Exception
    puts e.message
  end
end

control.send(Control::Start)
items.send("Hello")
control.send(Control::Stop)

sleep 5

And without rescue block:

$ crystal run /tmp/example.cr 
Unhandled exception:
can't execute `__temp_51[0]` at /tmp/example.cr:11:20: `__temp_51` has no type (Exception)
[4547076370] *CallStack::unwind:Array(Pointer(Void)) +82
[4547076273] *CallStack#initialize<CallStack>:Array(Pointer(Void)) +17
[4547076232] *CallStack::new:CallStack +40
[4547078929] *Exception#initialize<Exception, String, Nil>:CallStack +33
[4547078860] *Exception::new<String>:Exception +92
[4547063785] *raise<String>:NoReturn +9
[4547070820] ~fun_literal_21 +52
[4547132884] *Fiber#run<Fiber>:Nil +212
[4547065065] ~fun_literal_4 +9
enum Control
  Start
  Stop
end

items = Channel(String).new(10)
control = Channel(Control).new(10)

spawn do
  loop do
    index, value = Channel(String | Control).select(items, control)
    case value
    when String
      puts value
    when Control
      puts "control item"
    else
      puts "else"
    end
  end
end

control.send(Control::Start)
items.send("Hello")
control.send(Control::Stop)

sleep 5
@asterite
Copy link
Member

@DougEverly Definitely a bug, thanks for reporting.

But select is used like this:

index, value = Channel.select(items.receive_op, control.receive_op)

Like that it compiles and seems to work. Eventually we'll have a select expression to make that easier to write.

@asterite asterite added this to the 0.20.2 milestone Dec 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants