Crystal: Error creating Proc with explicit receiver

Created on 22 Mar 2019  ·  6Comments  ·  Source: crystal-lang/crystal

$crystal --version
Crystal 0.27.2 [60760a546] (2019-02-05)

LLVM: 4.0.0
Default target: x86_64-unknown-linux-gnu
a = 15
b = ->a.divisible_by?(Int32)
Module validation failed: Invalid bitcast
  %74 = bitcast i32 %73 to i8*, !dbg !19
 (Exception)
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
  from ???
Error: you've found a bug in the Crystal compiler. Please open an issue

Playground link

I've generally been having issues with trying to use Procs with a receiver. In Ruby I use the method method often. Crystal's syntax seems like it would be an improvement.

bug topiccodegen

All 6 comments

This is fixed in master. I fixed it in https://github.com/crystal-lang/crystal/pull/7334

@asterite Are you sure it's the same issue? The one you mentioned was about parsing, whereas this one parses well, and the error refers to LLVM.

Pretty sure. In the PR I mention that I also found bugs with creating procs for methods of primitive types and that I fixed that.

This does not produce the same error on the current master, as far as I can tell. Getting Crystal to compile on Ubuntu was interesting. But, uh:

~/s/c/crystal ❯❯❯ bin/crystal eval "a = 15; b = ->a.divisible_by?(Int32); pp [3,5,7].map(&b)"
Using compiled compiler at `.build/crystal'
[true, false, false]
~/s/c/crystal ❯❯❯ bin/crystal eval "a = 15; b = ->a.divisible_by?(Int32); pp [3,5,7].map(&b)"
Using compiled compiler at `.build/crystal'
[false, true, false]
~/s/c/crystal ❯❯❯ bin/crystal eval "a = 15; b = ->a.divisible_by?(Int32); pp [3,5,7].map(&b)"
Using compiled compiler at `.build/crystal'
[false, false, false]

That probably shouldn't do that?

~/s/c/crystal ❯❯❯ bin/crystal --version
Using compiled compiler at `.build/crystal'
Crystal 0.28.0-dev [5282fdf91] (2019-03-23)

LLVM: 4.0.1
Default target: x86_64-pc-linux-gnu

Yeah, I can confirm this non-deterministic behaviour on master.

with this:

a = 15
b = ->a.divisible_by?(Int32)
b.call(3)
b.call(3)
b.call(3)

The results will be wrong most of the time, but each call produces the same results: either all true or all false.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

pbrusco picture pbrusco  ·  3Comments

jhass picture jhass  ·  3Comments

lbguilherme picture lbguilherme  ·  3Comments

will picture will  ·  3Comments

RX14 picture RX14  ·  3Comments