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

Alias types in schema lead to a bug #85

Closed
vladfaust opened this issue Mar 31, 2019 · 3 comments
Closed

Alias types in schema lead to a bug #85

vladfaust opened this issue Mar 31, 2019 · 3 comments
Labels
bug Something isn't working
Milestone

Comments

@vladfaust
Copy link
Member

vladfaust commented Mar 31, 2019

  type payload : Bytes
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).

@vladfaust vladfaust added the bug Something isn't working label Mar 31, 2019
@vladfaust vladfaust changed the title type name : Bytes leads to a bug Alias types in schema lead to a bug Apr 2, 2019
@jkthorne
Copy link

jkthorne commented Apr 2, 2019

I have run into similar issues

@vladfaust vladfaust added this to the next patch milestone Apr 3, 2019
@jkthorne
Copy link

@vladfaust what did you do to fix this?

@vladfaust
Copy link
Member Author

NB: You can click the mentioned commit to see its code

image

These lines in particular have fixed the bug:

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants