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

Module validation failed with proc in recursive def #14596

Open
ASnow opened this issue May 15, 2024 · 3 comments
Open

Module validation failed with proc in recursive def #14596

ASnow opened this issue May 15, 2024 · 3 comments

Comments

@ASnow
Copy link

ASnow commented May 15, 2024

Bug Report

Module validation failed: Function return type does not match operand type of return inst!
  ret ptr %2, !dbg !152
 %"->" = type { ptr, ptr }Function return type does not match operand type of return inst!
  ret ptr %52, !dbg !173
 %"->" = type { ptr, ptr }Function return type does not match operand type of return inst!
  ret ptr %1, !dbg !210
 %"->" = type { ptr, ptr }Function return type does not match operand type of return inst!
  ret ptr %19, !dbg !244
 %"->" = type { ptr, ptr }Function return type does not match operand type of return inst!
  ret ptr %0, !dbg !263
 %"->" = type { ptr, ptr } (Exception)
  from /crystal/src/llvm/module.cr:73:9 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.cr:239:5 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'
Error: you've found a bug in the Crystal compiler. Please open an issue, including source code that will allow us to reproduce the bug: https://github.com/crystal-lang/crystal/issues

In docker image https://hub.docker.com/layers/crystallang/crystal/1.12-alpine/images/sha256-297e82182800ff101755a2a26de747d6654eae3b487eb108aeac3299f181408d?context=explore

@ASnow ASnow added the kind:bug label May 15, 2024
@Blacksmoke16
Copy link
Member

Can you share a minimal reproducible example that causes this error?

@ASnow
Copy link
Author

ASnow commented May 15, 2024

Sorry. It took times to find exception point.

alias DslReplaceCondsFn = -> Bool
alias DslReplaceConds = Array(DslReplaceConds) | DslReplaceCondsFn

  def _replace_map(cond : DslReplaceConds) : DslReplaceCondsFn
    if cond.is_a?(Array)
      cond_fns = cond.map { |x| _replace_map(x) }
      ->() { (cond_fns.all? { |fn| fn.call }) } # problem is here if write  "? true : false " problem wil be fixed
  else
  ->() { false }
   end
 end

_replace_map([-> () { true }, -> () { false }])

@HertzDevil
Copy link
Contributor

You could also write -> : Bool { cond_fns.all? { |fn| fn.call } }, since it looks like the compiler had issues inferring that return type.

Reduction: (note that recursive types are not needed here, only a recursive def)

class Foo
  @x = uninitialized -> Bool
end

def foo(cond) : -> Bool
  if cond.is_a?(Foo)
    -> { foo(cond.@x).call }
  else
    cond
  end
end

foo(Foo.new)

@straight-shoota straight-shoota changed the title compiler bug Module validation failed with proc in recursive def May 16, 2024
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

3 participants