Crystal: Compiler error on creating an array of hashes

Created on 10 Jul 2018  路  4Comments  路  Source: crystal-lang/crystal

Just hit this error;
````
BUG: trying to downcast DB::ResultSet+ <- PG::ResultSet
???
...
...

???
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
On doing
begin
rows = [] of Hash(String, String)
# DB operations
Cove::DB.query_all "select unqid, title, content, link, authorid from posts" do |rs|
rs.column_names.each do |col|
row = {col => rs.read(String) }
rows = rows + [row]
end

            end

````

bug compiler

Most helpful comment

require "pg"

rows = [] of Hash(String, String)
db = DB.open "foo"
db.query_all "bar" do |rs|
  rs.column_names.each do |col|
    row = {col => rs.read(String)}
    rows = rows + [row]
  end
end

reproduces.

All 4 comments

Running this gives Syntax error in eval:10: expecting identifier 'end', not 'EOF' and it would be required to use your Cove library to compile it. Can you provide code that doesn't requires your library?

Oh, Cove is just a namespace. I suppose this should work. You will need to create a postgres DB connection.

                rows = [] of Hash(String, String)
                DB     = PG.connect ENV["DATABASE_URL"]
                DB.query_all "select unqid, title, content, link, authorid from posts" do |rs|
                    rs.column_names.each do |col|
                        row = {col => rs.read(String) }
                        rows = rows + [row]
                    end

                end     

I think I'm getting this same error. I have this fork of Lucky. For me, running crystal spec/lucky/custom_tags_spec.cr throws this error:

BUG: trying to downcast Array(Symbol)+ <- Array(Symbol) (Exception)
  from Crystal::CodeGenVisitor#downcast<LLVM::Value, Crystal::Type+, Crystal::Type+, Bool>:LLVM::Value
  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::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::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::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::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 main
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

Seems to be the same trying to downcast Something+ <- Something

require "pg"

rows = [] of Hash(String, String)
db = DB.open "foo"
db.query_all "bar" do |rs|
  rs.column_names.each do |col|
    row = {col => rs.read(String)}
    rows = rows + [row]
  end
end

reproduces.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nabeelomer picture nabeelomer  路  3Comments

TechMagister picture TechMagister  路  3Comments

oprypin picture oprypin  路  3Comments

RX14 picture RX14  路  3Comments

lgphp picture lgphp  路  3Comments