Skip to content

Commit

Permalink
Compiler: give error if constant has NoReturn type (#6411)
Browse files Browse the repository at this point in the history
  • Loading branch information
asterite authored and Serdar Dogruyol committed Jul 20, 2018
1 parent 1b83706 commit 02a78a8
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions spec/compiler/semantic/const_spec.cr
Expand Up @@ -373,4 +373,17 @@ describe "Semantic: const" do
),
"can't return from constant"
end

it "errors if constant has NoReturn type (#6139)" do
assert_error %(
lib LibFoo
fun foo : NoReturn
end
FOO = LibFoo.foo
FOO
),
"constant FOO has illegal type NoReturn"
end
end
4 changes: 4 additions & 0 deletions src/compiler/crystal/semantic/cleanup_transformer.cr
Expand Up @@ -195,6 +195,10 @@ module Crystal
unless const.value.type?
node.raise "can't infer type of constant #{const} (maybe the constant refers to itself?)"
end

if const.value.type.no_return?
node.raise "constant #{const} has illegal type NoReturn"
end
end

node.value = node.value.transform self
Expand Down

0 comments on commit 02a78a8

Please sign in to comment.