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

Crystal::Def#owner cannot be nil (NilAssertionError) #11870

Open
elebow opened this issue Mar 4, 2022 · 1 comment
Open

Crystal::Def#owner cannot be nil (NilAssertionError) #11870

elebow opened this issue Mar 4, 2022 · 1 comment

Comments

@elebow
Copy link
Contributor

elebow commented Mar 4, 2022

Bug Report

Minimal reproduction code

module GreatApp
  ->{ super }
end
$ crystal run crystal_bug.cr
Crystal::Def#owner cannot be nil (NilAssertionError)
  from /crystal/src/compiler/crystal/syntax/ast.cr:179:20 in 'lookup_matches_without_splat'
  from /crystal/src/compiler/crystal/semantic/call.cr:130:17 in 'lookup_matches:with_autocast'
  from /crystal/src/compiler/crystal/semantic/call.cr:96:5 in 'recalculate'
  from /crystal/src/compiler/crystal/semantic/main_visitor.cr:1461:7 in 'visit'
  from /crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /crystal/src/compiler/crystal/semantic/semantic_visitor.cr:562:5 in 'accept'
  from /crystal/src/compiler/crystal/semantic/main_visitor.cr:697:11 in 'visit'
  from /crystal/src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from /crystal/src/compiler/crystal/semantic/main_visitor.cr:6:7 in 'semantic:cleanup'
  from /crystal/src/compiler/crystal/compiler.cr:172:14 in 'compile'
  from /crystal/src/compiler/crystal/command.cr:220:5 in 'run_command'
  from /crystal/src/compiler/crystal/command.cr:64:5 in '__crystal_main'
  from /crystal/src/crystal/main.cr:115:5 in 'main'
  from src/env/__libc_start_main.c:94: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
$ crystal -v
Crystal 1.3.2 [932f193ae] (2022-01-18)

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

OS is Debian stable (11.2)

@straight-shoota
Copy link
Member

Just to be clear: This should be a syntax error when super is used outside a def.

It might be more complicated when the proc literal is actually used in side a def.
However, the following code actually works - which is a bit surprising to me (but probably fine?):

class Foo
  def bar
    "Foo#bar"
  end
end
class Bar < Foo
  def bar
    -> { super }
  end
end
Bar.new.bar.call # => "Foo#bar"

previous_def is similar, but it has a nicer error message already:

->{ previous_def } # Error: there is no previous definition of '->'

Although it's a semantic error. It should already be a syntax error when previous_def is used outside a def.

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