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

Doesn't compile on 0.24.2 #83

Closed
andrewzah opened this issue Apr 11, 2018 · 5 comments
Closed

Doesn't compile on 0.24.2 #83

andrewzah opened this issue Apr 11, 2018 · 5 comments

Comments

@andrewzah
Copy link

andrewzah commented Apr 11, 2018

Error:

in lib/db/src/db/query_methods.cr:215: can't infer block return type, try to cast the block body with `as`. See: https://github.com/crystal-lang/crystal/wiki/Compiler-error-messages#cant-infer-block-return-type

      query_all(query, *args) do |rs|
      ^~~~~~~~~

crystal version:

Crystal 0.24.2 (2018-03-19)

LLVM: 6.0.0
Default target: x86_64-pc-linux-gnu

edit: expanded error trace:


in lib/micrate/src/micrate/cli.cr:7: instantiating 'Micrate:Module#up(DB::Database)'

        Micrate.up(db)
                ^~

in lib/micrate/src/micrate.cr:27: instantiating 'dbversion(DB::Database)'

    current = dbversion(db)
              ^~~~~~~~~

in lib/micrate/src/micrate.cr:16: instantiating 'Micrate::DB:Module#get_versions_last_first_order(DB::Database)'

      rows = DB.get_versions_last_first_order(db)
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

in lib/micrate/src/micrate/db.cr:30: instantiating 'DB::Database#query_all(String)'

      db.query_all "SELECT version_id, is_applied from micrate_db_version ORDER BY id DESC", as: {Int64, Bool}
         ^~~~~~~~~

in lib/db/src/db/query_methods.cr:215: can't infer block return type, try to cast the block body with `as`. See: https://github.com/crystal-lang/crystal/wiki/Compiler-error-messages#cant-infer-block-return-type

      query_all(query, *args) do |rs|
@bcardiff
Copy link
Member

Hi @azah that cast wont work becuase the intention is to return a specific tuple type, not just Type.

Probably there is an issue in the code you are not sharing yet.
Please, reduce the code / show the call for query_all or ask in Gitter / SO.

@andrewzah
Copy link
Author

andrewzah commented Apr 11, 2018

I'm using micrate, which as far as I can tell has this code:

    def self.get_versions_last_first_order(db)
      db.query_all "SELECT version_id, is_applied from micrate_db_version ORDER BY id DESC", as: {Int64, Bool}
    end

@andrewzah
Copy link
Author

An expanded error trace:


in lib/micrate/src/micrate/cli.cr:7: instantiating 'Micrate:Module#up(DB::Database)'

        Micrate.up(db)
                ^~

in lib/micrate/src/micrate.cr:27: instantiating 'dbversion(DB::Database)'

    current = dbversion(db)
              ^~~~~~~~~

in lib/micrate/src/micrate.cr:16: instantiating 'Micrate::DB:Module#get_versions_last_first_order(DB::Database)'

      rows = DB.get_versions_last_first_order(db)
                ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~

in lib/micrate/src/micrate/db.cr:30: instantiating 'DB::Database#query_all(String)'

      db.query_all "SELECT version_id, is_applied from micrate_db_version ORDER BY id DESC", as: {Int64, Bool}
         ^~~~~~~~~

in lib/db/src/db/query_methods.cr:215: can't infer block return type, try to cast the block body with `as`. See: https://github.com/crystal-lang/crystal/wiki/Compiler-error-messages#cant-infer-block-return-type

      query_all(query, *args) do |rs|

@andrewzah
Copy link
Author

query_all calls read which calls internal_read:

   # micrate.cr
    def query_migration_status(migration, db)
      db.query_all "SELECT tstamp, is_applied FROM micrate_db_version WHERE version_id=$1 ORDER BY tstamp DESC LIMIT 1", migration.version, as: {Time, Bool}
    end

   # lib/db/src/db/query_methods.cr
   def query_all(query, *args, as types : Tuple)
      query_all(query, *args) do |rs|
        rs.read(*types)
      end
    end

    # lib/db/src/db/result_set.cr
    def read(*types : Class)
      internal_read(*types)
    end

    private def internal_read(*types : *T) forall T
      {% begin %}
        Tuple.new(
          {% for type in T %}
            read({{type.instance}}),
          {% end %}
        )
      {% end %}
    end

@beta-ziliani
Copy link
Member

@andrewzah I assume we can close this one?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants