Skip to content

Commit

Permalink
Fix: broken binding generation when unexposed enum in struct field
Browse files Browse the repository at this point in the history
  • Loading branch information
olbat committed Mar 1, 2020
1 parent 8542199 commit 8a1d891
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
9 changes: 9 additions & 0 deletions spec/parser_spec.cr
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ describe Parser do
fields.first.type.should eq(PointerType.new(UnexposedType.new("foo")))
end

it "parses struct with unexposed enum" do
nodes = parse("struct point { enum { x, y } foo; };")
type = nodes.last.as(StructOrUnion)
fields = type.fields
node_ref = fields.first.type.as(NodeRef)
enum_def = node_ref.node.as(CrystalLib::Enum)
enum_def.values.size.should eq(2)
end

it "parses recursive struct" do
nodes = parse("struct point { struct point* x; };")
type = nodes.last.as(StructOrUnion)
Expand Down
2 changes: 2 additions & 0 deletions src/crystal_lib/parser.cr
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,8 @@ class CrystalLib::Parser
NodeRef.new(visit_struct_or_union_declaration(definition, :struct))
when .union_decl?
NodeRef.new(visit_struct_or_union_declaration(definition, :union))
when .enum_decl?
NodeRef.new(visit_enum_declaration(definition))
else
UnexposedType.new(type.cursor.spelling)
end
Expand Down

0 comments on commit 8a1d891

Please sign in to comment.