Skip to content

Commit

Permalink
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions spec/compiler/semantic/const_spec.cr
Original file line number Diff line number Diff line change
@@ -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
@@ -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

0 comments on commit 02a78a8

Please sign in to comment.