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

Nil assertion failed in codegen_fun when using closured object inside captured block inside CONST initializer #10474

Closed
RX14 opened this issue Mar 6, 2021 · 5 comments · Fixed by #10478
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic

Comments

@RX14
Copy link
Contributor

RX14 commented Mar 6, 2021

I was writing my first Crystal code for a while and I managed to hit this in 5 minutes! I think I have previous maintainer's bad luck.

Here's a minimal test case, which reproduces with --prelude=empty:

class Foo
  def bar
  end
end

def func(&block)
  block.call
end

CONST = begin
  foo = Foo.new
  func do
    foo.bar
  end
end

CONST

Backtrace:

Nil assertion failed (NilAssertionError)
  from /data/programming/crystal-lang/crystal/master/src/nil.cr:106:5 in 'not_nil!'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/codegen/fun.cr:103:47 in 'codegen_fun'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/codegen/fun.cr:51:3 in 'codegen_fun:fun_module_info:is_fun_literal:is_closure'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/codegen/codegen.cr:549:17 in 'visit'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/codegen/codegen.cr:2184:7 in 'accept'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/codegen/call.cr:318:5 in 'codegen_call_with_block_as_fun_literal'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/codegen/call.cr:30:9 in 'visit'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/codegen/codegen.cr:2184:7 in 'accept'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/codegen/codegen.cr:619:9 in 'visit'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/codegen/codegen.cr:2184:7 in 'accept'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/codegen/const.cr:159:13 in 'create_initialize_const_function'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/codegen/const.cr:131:56 in 'initialize_const'
  from /data/programming/crystal-lang/crystal/master/src/compiler/crystal/codegen/codegen.cr:930:9 in 'codegen_assign'
... boring codegen visitor doing it's visiting, clipped for length
@asterite
Copy link
Member

asterite commented Mar 6, 2021

Hi!

I'd love to help but I can't compile the compiler anymore :-(

Undefined symbols for architecture x86_64:
  "_roundeven", referenced from:
      _*Float64#round_even:Float64 in F-loat64.o

This is on Mac OSX, LLVM 11.1.0

@straight-shoota Any ideas?

@asterite
Copy link
Member

asterite commented Mar 6, 2021

By the way, the issue seems to be that closures don't work right now inside const initializations. It should be easy to fix... once I can get things compiling again. Maybe I'll stick with LLVM 10 for now.

@asterite
Copy link
Member

asterite commented Mar 6, 2021

Same error... :-(

@straight-shoota
Copy link
Member

@asterite This is weird, and definitely a different issue. You can just revert the last commit (or just checkout master^).

@RX14
Copy link
Contributor Author

RX14 commented Mar 6, 2021

I'm looking into a patch for this, it's interesting poking around in the compiler anyway :)

@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Mar 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants