Skip to content

Commit

Permalink
feat: bitfield macro outside of a bitfield error message
Browse files Browse the repository at this point in the history
to help simplify debugging with a less obscure error message
  • Loading branch information
stakach committed Nov 17, 2020
1 parent c7d6c13 commit a08c239
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion shard.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: bindata
version: 1.8.0
version: 1.8.1

development_dependencies:
ameba:
Expand Down
3 changes: 2 additions & 1 deletion src/bindata.cr
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,8 @@ abstract class BinData
end

macro bits(size, name, value = nil, default = nil)
%field = @@bit_fields["{{KLASS_NAME[0]}}_{{INDEX[0]}}"]
%field = @@bit_fields["{{KLASS_NAME[0]}}_{{INDEX[0]}}"]?
raise "#{KLASS_NAME[0]}#{ '#' }{{name}} is not defined in a bitfield. Using bitfield macro outside of a bitfield" unless %field
%field.bits({{size}}, {{name.id.stringify}})

{% if size <= 8 %}
Expand Down

0 comments on commit a08c239

Please sign in to comment.