crystal-lang / crystal

The Crystal Programming Language
https://crystal-lang.org
Apache License 2.0
19.26k stars 1.61k forks source link

BUG: unhandled primitive in codegen: slice_literal #14572

Open BlobCodes opened 2 months ago

BlobCodes commented 2 months ago

Bug Report

The following code results in a compiler bug:

a = Slice(UInt8).literal(0)
b = Slice(UInt8).literal(1)

This only happens when both variables are not constants (or if there is no assignment at all) and if both literals have the same amount of elements. This also doesn't happen if the two literals have different types (ex. Slice(UInt32) and Slice(UInt8)).

Stack trace:

BUG: unhandled primitive in codegen: slice_literal (Exception)
  from /crystal/src/compiler/crystal/codegen/codegen.cr:2392:9 in 'visit'
  from /crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /crystal/src/compiler/crystal/codegen/codegen.cr:2392:9 in 'codegen_assign'
  from /crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /crystal/src/enumerable.cr:510:7 in '??'
  from /crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /crystal/src/compiler/crystal/codegen/codegen.cr:2362:7 in 'codegen'
  from /crystal/src/compiler/crystal/compiler.cr:202:16 in 'compile:combine_rpath'
  from /crystal/src/compiler/crystal/compiler.cr:195:56 in 'compile:combine_rpath'
  from /crystal/src/compiler/crystal/command/eval.cr:30:5 in 'eval'
  from /crystal/src/compiler/crystal/command.cr:126:12 in 'run'
  from /crystal/src/compiler/crystal.cr:11:1 in '__crystal_main'
  from /crystal/src/crystal/main.cr:129:5 in 'main'
  from src/env/__libc_start_main.c:95:2 in 'libc_start_main_stage2'

⬢[blob@toolbox ~]$ crystal -v
Crystal 1.12.1 [4cea10199] (2024-04-11)

LLVM: 15.0.7
Default target: x86_64-unknown-linux-gnu

⬢[blob@toolbox ~]$ crystal env
CRYSTAL_CACHE_DIR=/var/home/blob/.cache/crystal
CRYSTAL_PATH=lib:/usr/share/crystal/src
CRYSTAL_VERSION=1.12.1
CRYSTAL_LIBRARY_PATH=/usr/lib64/crystal
CRYSTAL_LIBRARY_RPATH=''
CRYSTAL_OPTS=''