Skip to content

Commit

Permalink
Compiler: error on enum without members. Fixes #3447
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite committed Dec 7, 2016
1 parent ed790ae commit f980578
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
8 changes: 8 additions & 0 deletions spec/compiler/semantic/enum_spec.cr
Expand Up @@ -298,4 +298,12 @@ describe "Semantic: enum" do
),
"can't inherit Enum. Use the enum keyword to define enums"
end

it "errors on enum without members (#3447)" do
assert_error %(
enum Foo
end
),
"enum Foo must have at least one member"
end
end
4 changes: 4 additions & 0 deletions src/compiler/crystal/semantic/top_level_visitor.cr
Expand Up @@ -485,6 +485,10 @@ class Crystal::TopLevelVisitor < Crystal::SemanticVisitor
is_flags: is_flags)
end

if enum_type.types.empty?
node.raise "enum #{node.name} must have at least one member"
end

unless existed
if is_flags
unless enum_type.types["None"]?
Expand Down

0 comments on commit f980578

Please sign in to comment.