crystal-lang / crystal

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

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

Open Blacksmoke16 opened 5 years ago

Blacksmoke16 commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

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.

asterite commented 5 years ago

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 commented 5 years ago

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 commented 5 years ago

@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 commented 5 years ago

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 commented 2 years ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 3 months ago

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 commented 3 months ago

Adding a Nil type restriction fixes the error for the reductions https://github.com/crystal-lang/crystal/issues/7461#issuecomment-465644071 and https://github.com/crystal-lang/crystal/issues/7461#issuecomment-465655118 @Blacksmoke16 could you check with your original code?

I disagree on this reasoning for rejecting a workaround in https://github.com/crystal-lang/crystal/pull/7474#issuecomment-466357638

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 commented 3 months ago

@Blacksmoke16 could you check with your original code?

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