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

Compiler: give error if constant has NoReturn type #6411

Merged
merged 1 commit into from
Jul 20, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions spec/compiler/semantic/const_spec.cr
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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