crystal icon indicating copy to clipboard operation
crystal copied to clipboard

Interpreter: Reached the unreachable with athena-validator callback constraint

Open cyangle opened this issue 3 years ago • 0 comments

Bug Report

Example validator usage:

require "../../src/athena-validator"

class A
end

callback = AVD::Constraints::Callback::CallbackProc.new do |value, context|
  value2 = value.get(A)
  context.add_violation "different violation"
end
constraint = AVD::Constraints::Callback.new callback: callback

pp AVD.validator.validate(A.new, constraint)

Works fine in compiled mode but fails in interpreted mode:

In: Athena::Validator::Constraints::Callback::ValueContainer+#get
Node: raise "unreachable"
Reached the unreachable (Exception)
  from /home/chao/git/personal/crystal/src/compiler/crystal/interpreter/interpreter.cr:337:7 in 'interpret'
  from /home/chao/git/personal/crystal/src/compiler/crystal/interpreter/interpreter.cr:235:13 in 'interpret'
  from /home/chao/git/personal/crystal/src/compiler/crystal/interpreter/repl.cr:100:5 in 'interpret_and_exit_on_error'
  from /home/chao/git/personal/crystal/src/gc/boehm.cr:129:5 in 'run'
  from /home/chao/git/personal/crystal/src/compiler/crystal/command.cr:51:5 in '__crystal_main'
  from /home/chao/git/personal/crystal/src/crystal/main.cr:115:5 in 'main'
  from /lib/x86_64-linux-gnu/libc.so.6 in '??'
  from /lib/x86_64-linux-gnu/libc.so.6 in '__libc_start_main'
  from /home/chao/git/personal/crystal/.build/crystal in '_start'
  from ???

And you'll get index out of bounds error after changing value2 to value in the example code:

In: Athena::Validator::Constraints::Callback::ValueContainer+#get
Node: self.is_a?(Athena::Validator::Constraints::Callback::Value(A))
Index out of bounds (IndexError)
  from /home/chao/git/personal/crystal/src/pointer.cr:516:5 in 'interpret'
  from /home/chao/git/personal/crystal/src/compiler/crystal/interpreter/interpreter.cr:235:13 in 'interpret'
  from /home/chao/git/personal/crystal/src/compiler/crystal/interpreter/repl.cr:100:5 in 'interpret_and_exit_on_error'
  from /home/chao/git/personal/crystal/src/gc/boehm.cr:129:5 in 'run'
  from /home/chao/git/personal/crystal/src/compiler/crystal/command.cr:51:5 in '__crystal_main'
  from /home/chao/git/personal/crystal/src/crystal/main.cr:115:5 in 'main'
  from /lib/x86_64-linux-gnu/libc.so.6 in '??'
  from /lib/x86_64-linux-gnu/libc.so.6 in '__libc_start_main'
  from /home/chao/git/personal/crystal/.build/crystal in '_start'
  from ???

Crystal version:

Crystal 1.6.0-dev [8cb915f95] (2022-08-01)

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

OS: Ubuntu 22.04

cyangle avatar Aug 01 '22 22:08 cyangle