Testing a supposed map for being nil crashes SP

supposedMap = nil
if supposedMap == nil
  puts "Operator == works fine - 1"
end
supposedMap = map foo: 1
if supposedMap == nil
  puts "Operator == works fine - 2"
end

gives the following output:

{run: 2683, time: 0.0}
 └─ "Operator == works fine - 1"

and the following crash error:

untime Error: [buffer 3, line 6] - NoMethodError
Thread death!
 undefined method `map' for nil:NilClass

        other.map == @map
             ^^^^
C:/Program Files/Sonic Pi/app/server/ruby/core.rb:411:in `=='
workspace_three:6:in `block (2 levels) in __spider_eval'
C:/Program Files/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:905:in `eval'
C:/Program Files/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:905:in `block (2 levels) in __spider_eval'
C:/Program Files/Sonic Pi/app/server/ruby/lib/sonicpi/runtime.rb:1169:in `block (2 levels) in __in_thread'

I can understand that testing for equality between a map and another map can be tricky. But at least, it should be possible to test a map equality against something else than a map, e.g. nil.

I’ve sent a PR that I think should fix this, let’s see what @samaaron thinks.

@oor the fix was merged, so it should work better in the next release.

1 Like