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

Fix: broken binding generation when unexposed enum in struct field #67

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions spec/parser_spec.cr
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
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