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

BUG: `def consume_formatted_substitution ... at .../string/formatter.cr:53:11 has no type #7461

Open
Blacksmoke16 opened this issue Feb 20, 2019 · 12 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler

Comments

@Blacksmoke16
Copy link
Member

Blacksmoke16 commented Feb 20, 2019

error:

BUG: `def consume_formatted_substitution
  key = consume_substitution_key('>')
  next_char
  arg = current_arg
  if if false
    arg.is_a?(Hash)
  else
    false
  end
    target_arg = arg[key]
  else
    raise(ArgumentError.new("One hash or named tuple required"))
  end
end` at /usr/share/crystal/src/string/formatter.cr:53:11 has no type (Exception)
  from ???
  from ???
  from ???
  from ???
  from ???
  ...
  from ???
  from ???
  from ???
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

I do not have code that can reproduce it atm. Came across it while i was writing a tutorial for Athena + Granite. I can share the repo once its done if anyone wants to poke around.

The issue seems to be with something Athena is doing. I'll poke around later and see if i can figure anything out.

@Blacksmoke16
Copy link
Member Author

Am able to easily reproduce it. Working on trimming it down atm. The error message is slightly different on Mac.

BUG: `def consume_formatted_substitution
  key = consume_substitution_key('>')
  next_char
  arg = current_arg
  if if false
    arg.is_a?(Hash)
  else
    false
  end
    target_arg = arg[key]
  else
    raise(ArgumentError.new("One hash or named tuple required"))
  end
end` at /usr/local/Cellar/crystal/0.27.0/src/string/formatter.cr:53:11 has no type (Exception)
  from Crystal::Def+@Crystal::ASTNode#type:Crystal::Type+
  from Crystal::CodeGenVisitor#codegen_fun_signature_non_external<String, Crystal::Def+, Crystal::Type+, Bool, Bool>:Array(Crystal::Arg)
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil)
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#prepare_call_args_non_external<Crystal::Call, Crystal::Def+, Crystal::Type+>:Tuple(Array(LLVM::Value), Bool)
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#prepare_call_args_non_external<Crystal::Call, Crystal::Def+, Crystal::Type+>:Tuple(Array(LLVM::Value), Bool)
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#prepare_call_args_non_external<Crystal::Call, Crystal::Def+, Crystal::Type+>:Tuple(Array(LLVM::Value), Bool)
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil)
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#prepare_call_args_non_external<Crystal::Call, Crystal::Def+, Crystal::Type+>:Tuple(Array(LLVM::Value), Bool)
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil)
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#prepare_call_args_non_external<Crystal::Call, Crystal::Def+, Crystal::Type+>:Tuple(Array(LLVM::Value), Bool)
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#prepare_call_args_non_external<Crystal::Call, Crystal::Def+, Crystal::Type+>:Tuple(Array(LLVM::Value), Bool)
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#prepare_call_args_non_external<Crystal::Call, Crystal::Def+, Crystal::Type+>:Tuple(Array(LLVM::Value), Bool)
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#visit<Crystal::Assign>:(Bool | Nil)
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::CodeGenVisitor#codegen_fun<String, Crystal::Def+, Crystal::Type+, Bool, Crystal::CodeGenVisitor::ModuleInfo, Bool, Bool>:LLVM::Function
  from Crystal::CodeGenVisitor#target_def_fun<Crystal::Def+, Crystal::Type+>:LLVM::Function
  from Crystal::CodeGenVisitor#visit<Crystal::Call>:Bool
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::ASTNode+@Crystal::ASTNode#accept<Crystal::CodeGenVisitor>:Nil
  from Crystal::Compiler#codegen<Crystal::Program, Crystal::ASTNode+, Array(Crystal::Compiler::Source), String>:(Tuple(Array(Crystal::Compiler::CompilationUnit), Array(String)) | Nil)
  from Crystal::Compiler#compile<Array(Crystal::Compiler::Source), String>:Crystal::Compiler::Result
  from Crystal::Command#run_command<Bool>:Nil
  from Crystal::Command#run:(Bool | Crystal::Compiler::Result | Nil)
  from __crystal_main
  from main

@Blacksmoke16
Copy link
Member Author

Blacksmoke16 commented Feb 20, 2019

Reduced:

https://play.crystal-lang.org/#/r/6bgt

require "crypto/bcrypt/password"

class FooHandler 
 def initialize
    proc = ->(vals : Hash(String, String?)) do
      ->{Crypto::Bcrypt::Password.create("monkey").to_s }.call
    end
 end
end

def run(handlers : Array(FooHandler) = [FooHandler.new])
end

run

s/o to @konovod for a further reduction.

@Blacksmoke16 Blacksmoke16 changed the title BUG: `def consume_formatted_substitution ... at /usr/share/crystal/src/string/formatter.cr:53:11 has no type (Exception) BUG: `def consume_formatted_substitution ... at .../string/formatter.cr:53:11 has no type Feb 20, 2019
@jhass jhass added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler labels Feb 20, 2019
@asterite
Copy link
Member

Reduced a bit more:

class Foo
  def initialize
    "" % 1
  end
end

def run(x : Foo = Foo.new)
end

run

Probably can be reduced further by starting to reduce String::Formatter.

@Blacksmoke16
Copy link
Member Author

Blacksmoke16 commented Feb 20, 2019

Got stack trace to display differently again if its helpful for anything

BUG: `def consume_formatted_substitution
  key = consume_substitution_key('>')
  next_char
  arg = current_arg
  target_arg = nil
  if if false
    arg.is_a?(Hash)
  else
    false
  end
    target_arg = arg[key]
  else
    raise(ArgumentError.new("One hash or named tuple required"))
  end
end` at /Users/georgedietrich/Desktop/crystal-master/src/string/formatter.cr:53:11 has no type (Exception)
  from src/compiler/crystal/semantic/bindings.cr:13:18 in 'type'
  from src/compiler/crystal/codegen/fun.cr:252:24 in 'codegen_fun_signature_non_external'
  from src/compiler/crystal/codegen/fun.cr:210:7 in 'codegen_fun_signature'
  from src/compiler/crystal/codegen/fun.cr:82:14 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:51:3 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:8:54 in 'target_def_fun'
  from src/compiler/crystal/codegen/call.cr:408:12 in 'codegen_call'
  from src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:605:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:777:7 in 'codegen_if_branch'
  from src/compiler/crystal/codegen/codegen.cr:768:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:777:7 in 'codegen_if_branch'
  from src/compiler/crystal/codegen/codegen.cr:769:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:605:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/fun.cr:144:9 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:51:3 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:8:54 in 'target_def_fun'
  from src/compiler/crystal/codegen/call.cr:408:12 in 'codegen_call'
  from src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:777:7 in 'codegen_if_branch'
  from src/compiler/crystal/codegen/codegen.cr:768:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:777:7 in 'codegen_if_branch'
  from src/compiler/crystal/codegen/codegen.cr:769:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:605:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:804:11 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/fun.cr:144:9 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:51:3 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:8:54 in 'target_def_fun'
  from src/compiler/crystal/codegen/call.cr:408:12 in 'codegen_call'
  from src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:68:5 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:68:5 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:605:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/call.cr:286:13 in 'codegen_call_with_block'
  from src/compiler/crystal/codegen/call.cr:32:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/call.cr:286:13 in 'codegen_call_with_block'
  from src/compiler/crystal/codegen/call.cr:32:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/fun.cr:144:9 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:51:3 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:8:54 in 'target_def_fun'
  from src/compiler/crystal/codegen/call.cr:408:12 in 'codegen_call'
  from src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:605:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/fun.cr:144:9 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:51:3 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:8:54 in 'target_def_fun'
  from src/compiler/crystal/codegen/call.cr:408:12 in 'codegen_call'
  from src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/fun.cr:144:9 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:51:3 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:8:54 in 'target_def_fun'
  from src/compiler/crystal/codegen/call.cr:408:12 in 'codegen_call'
  from src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/fun.cr:144:9 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:51:3 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:8:54 in 'target_def_fun'
  from src/compiler/crystal/codegen/call.cr:408:12 in 'codegen_call'
  from src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:605:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/fun.cr:144:9 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:51:3 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:8:54 in 'target_def_fun'
  from src/compiler/crystal/codegen/call.cr:408:12 in 'codegen_call'
  from src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:941:9 in 'codegen_assign'
  from src/compiler/crystal/codegen/codegen.cr:905:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:605:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/fun.cr:144:9 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:51:3 in 'codegen_fun'
  from src/compiler/crystal/codegen/fun.cr:8:54 in 'target_def_fun'
  from src/compiler/crystal/codegen/call.cr:408:12 in 'codegen_call'
  from src/compiler/crystal/codegen/call.cr:35:7 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:605:9 in 'visit'
  from src/compiler/crystal/syntax/visitor.cr:27:12 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:2074:7 in 'accept'
  from src/compiler/crystal/codegen/codegen.cr:65:7 in 'codegen'
  from src/compiler/crystal/codegen/codegen.cr:63:5 in 'codegen:debug:single_module'
  from src/compiler/crystal/compiler.cr:22:7 in 'codegen'
  from src/compiler/crystal/compiler.cr:153:16 in 'compile'
  from src/compiler/crystal/command.cr:258:7 in 'compile'
  from src/compiler/crystal/command.cr:177:14 in 'run_command'
  from src/compiler/crystal/command.cr:99:7 in 'run'
  from src/compiler/crystal/command.cr:46:5 in 'run'
  from src/compiler/crystal/command.cr:45:3 in 'run'
  from src/compiler/crystal.cr:8:1 in '__crystal_main'
  from src/crystal/main.cr:97:5 in 'main_user_code'
  from src/crystal/main.cr:86:7 in 'main'
  from src/crystal/main.cr:106:3 in 'main'

@Blacksmoke16
Copy link
Member Author

Blacksmoke16 commented Feb 20, 2019

@asterite I don't really know what im doing but adding unless arg.empty? seems to fix it?

https://play.crystal-lang.org/#/r/6bi4

@asterite
Copy link
Member

Reduced more:

lib LibC
  fun exit(Int32) : NoReturn
end

class Foo
  def initialize
    arg = 1
    LibC.exit(0) unless arg.is_a?(String)
    unknown arg
  end
end

def run(x : Foo = Foo.new)
end

run

It's strange because if you remove the : Foo type restriction it works.

@matthewmcgarvey
Copy link
Contributor

Bumping to say that I just ran into this. I can run crystal spec on my project and it completes successfully, but if I run crystal spec path/to/file_spec.cr it causes this error.

@naqvis
Copy link
Contributor

naqvis commented Mar 8, 2023

Bumping to say that I just ran into this. I can run crystal spec on my project and it completes successfully, but if I run crystal spec path/to/file_spec.cr it causes this error.

Same behavior seen

@naqvis
Copy link
Contributor

naqvis commented May 6, 2023

I have tested Crystal versions 1.5.2 to 1.8.1 and this consume_substitution bug still persists. Do we have any plan or roadmap to get this issue fixed in future versions?

@jgaskins
Copy link
Contributor

jgaskins commented Apr 1, 2024

For folks discovering this issue because you're seeing this error in your specs and need a workaround:

Some calls in the askn/faker shard use string formatting. I'm working around the compiler bug by removing some usage of Faker and replacing it with Random::Secure.hex calls. The downside is that it makes test data more opaque and may make some DB queries slower in tests, but my code is back to compiling now.

straight-shoota added a commit to straight-shoota/crystal that referenced this issue Apr 4, 2024
…itution`

This is a workaround for a compiler error that fails to type this
method (crystal-lang#7461).
@straight-shoota
Copy link
Member

straight-shoota commented Apr 4, 2024

Adding a Nil type restriction fixes the error for the reductions #7461 (comment) and #7461 (comment)
@Blacksmoke16 could you check with your original code?

I disagree on this reasoning for rejecting a workaround in #7474 (comment)

Sorry, but this is a compiler bug. Something should be fixed in the compiler. We shouldn't workaround the issue because then we'll forget about it and it will be triggered in a different situation.

Yes it's a compiler bug. But it affects people using stdlib features. We haven't managed to identify, let alone fix, the cause of this bug in 5 years. So leaving it unpatched hasn't helped finding a proper solution. The least we can do is apply a simple workaround to make this smooth for stdlib API consumers.

@Blacksmoke16
Copy link
Member Author

@Blacksmoke16 could you check with your original code?

Unfortunately at this point I'm not sure what that code was :/

@straight-shoota straight-shoota removed their assignment Apr 24, 2024
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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants