Skip to content

Alias types in schema lead to a bug #85

Description

@vladfaust
  type payload : Bytes
Details
in src/worcr/model/job.cr:3: expanding macro

    include Onyx::SQL::Model
    ^

in macro 'included' /home/faust/Projects/worcr2/worcr/lib/onyx-sql/src/onyx-sql/model/enums.cr:2, line 12:

   1.     macro finished
   2.       
   3.         {% getters = @type.methods.select do |_def|
   4.   _def.body.is_a?(InstanceVar)
   5. end
   6. fields = getters.select do |g|
   7.   if g.return_type.is_a?(Union)
   8.     type = g.return_type.types.find do |t|
   9.       !t.is_a?(Nil)
  10.     end
  11.     if type.resolve < Enumerable
> 12.       !(type.type_vars.first.resolve < Onyx::SQL::Model)
  13.     else
  14.       !(type.resolve < Onyx::SQL::Model)
  15.     end
  16.   end
  17. end
  18. references = getters.select do |g|
  19.   if g.return_type.is_a?(Union)
  20.     type = g.return_type.types.find do |t|
  21.       !t.is_a?(Nil)
  22.     end
  23.     if type.resolve < Enumerable
  24.       type.type_vars.first.resolve < Onyx::SQL::Model
  25.     else
  26.       type.resolve < Onyx::SQL::Model
  27.     end
  28.   end
  29. end
  30.  %}
  31. 
  32.         {% if fields.size > 0 %}
  33.           enum Field
  34.             {% for field in fields %}
  35.               {{ field.body.name[1..-1].camelcase }}
  36.             {% end %}
  37.           end
  38.         {% else %}
  39.           enum Field
  40.             Nop
  41.           end
  42.         {% end %}
  43. 
  44.         {% if references.size > 0 %}
  45.           enum Reference
  46.             {% for reference in references %}
  47.               {{ reference.body.name[1..-1].camelcase }}
  48.             {% end %}
  49.           end
  50.         {% else %}
  51.           enum Reference
  52.             Nop
  53.           end
  54.         {% end %}
  55.       
  56.     end
  57.   

expanding macro
in macro 'type' /home/faust/Projects/worcr2/worcr/lib/onyx-sql/src/onyx-sql/model/schema.cr:95, line 1:

>  1.     property payload : Bytes | Nil
   2. 
   3.     def payload!
   4.       @payload.not_nil!
   5.     end
   6. 
   7.     macro finished
   8.       
   9.     end
  10.   

expanding macro
in macro 'property' expanded macro: macro_140665494030752:583, line 6:

   1.       
   2.         
   3.           
   4.             @payload : Bytes | Nil
   5. 
>  6.             def payload : Bytes | Nil
   7.               @payload
   8.             end
   9. 
  10.             def payload=(@payload : Bytes | Nil)
  11.             end
  12.           
  13.         
  14.       
  15.     

undefined macro method 'Path#type_vars'

Current workaround: use Slice(UInt8) (i.e. do not use aliases).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions