Rename Void to Never

Void is confusing as in C it's used for void* pointers, which are more
akin to dynamically typed pointers. The name Never more clearly
indicates that something (e.g. returning) will never happen.
parent 98544de7
Pipeline #101388743 passed with stages
in 21 minutes and 39 seconds
......@@ -147,7 +147,7 @@ require 'inkoc/type_system/dynamic'
require 'inkoc/type_system/optional'
require 'inkoc/type_system/self_type'
require 'inkoc/type_system/error'
require 'inkoc/type_system/void'
require 'inkoc/type_system/never'
require 'inkoc/type_system/database'
require 'inkoc/codegen/compiled_code'
require 'inkoc/codegen/instruction'
......
......@@ -44,8 +44,8 @@ module Inkoc
name == Config::DYNAMIC_TYPE
end
def void_type?
name == Config::VOID_TYPE
def never_type?
name == Config::NEVER_TYPE
end
def visitor_method
......
......@@ -87,7 +87,7 @@ module Inkoc
false
end
def void_type?
def never_type?
false
end
......
......@@ -41,8 +41,8 @@ module Inkoc
late_binding? ? :on_self_type_with_late_binding : :on_self_type
when Config::DYNAMIC_TYPE
:on_dynamic_type
when Config::VOID_TYPE
:on_void_type
when Config::NEVER_TYPE
:on_never_type
else
:on_type_name
end
......
......@@ -6,7 +6,7 @@ module Inkoc
attr_accessor :type
def block_type
TypeSystem::Void.new
TypeSystem::Never.new
end
end
end
......
......@@ -55,7 +55,7 @@ module Inkoc
MODULE_TYPE = 'Module'
SELF_TYPE = 'Self'
DYNAMIC_TYPE = 'Dynamic'
VOID_TYPE = 'Void'
NEVER_TYPE = 'Never'
MODULES_ATTRIBUTE = 'Modules'
# The name of the constant to use as the receiver for raw instructions.
......@@ -86,7 +86,7 @@ module Inkoc
MODULE_GLOBAL,
RAW_INSTRUCTION_RECEIVER,
SELF_TYPE,
VOID_TYPE,
NEVER_TYPE,
DYNAMIC_TYPE
]
).freeze
......
......@@ -132,8 +132,8 @@ module Inkoc
wrap_optional_type(node, TypeSystem::Dynamic.new)
end
def on_void_type(node, _)
wrap_optional_type(node, TypeSystem::Void.new)
def on_never_type(node, _)
wrap_optional_type(node, TypeSystem::Never.new)
end
def on_type_name(node, scope)
......@@ -484,7 +484,7 @@ module Inkoc
expected_type =
block_type.return_type.resolve_self_type(scope.self_type)
if !type.void? && !type.type_compatible?(expected_type, @state)
if !type.never? && !type.type_compatible?(expected_type, @state)
loc = node.location_of_last_expression
diagnostics.return_type_error(expected_type, type, loc)
......@@ -514,7 +514,7 @@ module Inkoc
# A "return" statement itself will never return a value. For example,
# `let x = return 10` would never assign a value to `x`.
TypeSystem::Void.new
TypeSystem::Never.new
end
def on_try(node, scope)
......@@ -595,7 +595,7 @@ module Inkoc
scope.block_type.throw_type = type if scope.block_type.infer_throw_type?
TypeSystem::Void.new
TypeSystem::Never.new
end
def on_object(node, scope)
......@@ -1116,7 +1116,7 @@ module Inkoc
end
def on_raw_copy_blocks(*)
TypeSystem::Void.new
TypeSystem::Never.new
end
def on_raw_integer_to_string(*)
......@@ -1319,7 +1319,7 @@ module Inkoc
end
def on_raw_array_clear(*)
TypeSystem::Void.new
TypeSystem::Never.new
end
def on_raw_array_remove(node, _)
......@@ -1403,11 +1403,11 @@ module Inkoc
end
def on_raw_process_suspend_current(*)
TypeSystem::Void.new
TypeSystem::Never.new
end
def on_raw_process_terminate_current(*)
TypeSystem::Void.new
TypeSystem::Never.new
end
def on_raw_remove_attribute(node, _)
......@@ -1502,11 +1502,11 @@ module Inkoc
end
def on_raw_panic(*)
TypeSystem::Void.new
TypeSystem::Never.new
end
def on_raw_exit(*)
TypeSystem::Void.new
TypeSystem::Never.new
end
def on_raw_platform(*)
......@@ -1568,7 +1568,7 @@ module Inkoc
end
def on_raw_byte_array_clear(*)
TypeSystem::Void.new
TypeSystem::Never.new
end
def on_raw_byte_array_equals(*)
......
......@@ -2,20 +2,20 @@
module Inkoc
module TypeSystem
class Void
class Never
include Type
include NewInstance
def void?
def never?
true
end
def type_name
Config::VOID_TYPE
Config::NEVER_TYPE
end
def type_compatible?(_other, *)
# Void is compatible with everything else because it never returns. This
# Never is compatible with everything else because it never returns. This
# allows one to write code such as:
#
# try { foo } else { vm.panic('oops') }
......
......@@ -45,7 +45,7 @@ module Inkoc
false
end
def void?
def never?
false
end
......
......@@ -1422,7 +1422,7 @@ describe Inkoc::Pass::DefineType do
describe '#on_return' do
context 'when used inside a method' do
it 'returns a Void type' do
it 'returns a Never type' do
# An explicit return statement is a block return, thus the body that
# contains it won't return anything (unless the body is in a method).
body = parse_source('def foo { return 10 }')
......@@ -1435,7 +1435,7 @@ describe Inkoc::Pass::DefineType do
pass.define_type(body, type_scope)
pass.process_deferred_methods
expect(ret_node.type).to be_void
expect(ret_node.type).to be_never
end
it 'does not produce any errors when the return type is compatible' do
......@@ -1458,7 +1458,7 @@ describe Inkoc::Pass::DefineType do
it 'produces an error' do
type = expression_type('return 10')
expect(type).to be_void
expect(type).to be_never
expect(state.diagnostics.errors?).to eq(true)
end
end
......@@ -1603,10 +1603,10 @@ describe Inkoc::Pass::DefineType do
end
describe '#on_throw' do
it 'returns a void type' do
it 'returns a never type' do
type = expression_type('throw 10')
expect(type).to be_void
expect(type).to be_never
end
it 'infers the throw type of the surrounding closure' do
......@@ -2038,11 +2038,11 @@ describe Inkoc::Pass::DefineType do
expect(type.return_type.type).to be_self_type
end
it 'supports returning Void' do
type = expression_type('def foo -> Void {}')
it 'supports returning Never' do
type = expression_type('def foo -> Never {}')
expect(type).to be_method
expect(type.return_type).to be_void
expect(type.return_type).to be_never
end
end
......
......@@ -2,7 +2,7 @@
require 'spec_helper'
describe Inkoc::TypeSystem::Void do
describe Inkoc::TypeSystem::Never do
let(:state) { Inkoc::State.new(Inkoc::Config.new) }
describe '#type_compatible?' do
......@@ -14,7 +14,7 @@ describe Inkoc::TypeSystem::Void do
expect(ours.type_compatible?(theirs, state)).to eq(true)
end
it 'returns true when comparing with another void type' do
it 'returns true when comparing with another never type' do
theirs = described_class.new
expect(ours.type_compatible?(theirs, state)).to eq(true)
......@@ -26,7 +26,7 @@ describe Inkoc::TypeSystem::Void do
expect(ours.type_compatible?(theirs, state)).to eq(true)
end
it 'returns true when comparing with an optional void type' do
it 'returns true when comparing with an optional never type' do
theirs = Inkoc::TypeSystem::Optional.new(described_class.new)
expect(ours.type_compatible?(theirs, state)).to eq(true)
......
......@@ -209,7 +209,7 @@ impl Block {
#
# number += 1
# }.loop
def loop -> Void {
def loop -> Never {
call
loop
}
......
......@@ -235,7 +235,7 @@ def suspend(minimum: ToFloat = 0.0) -> Nil {
# # This code will never run because at this point the process has been
# # terminated.
# stdout.print('after')
def terminate -> Void {
def terminate -> Never {
_INKOC.process_terminate_current
}
......@@ -408,6 +408,6 @@ def pinned!(T)(block: do -> T) -> T {
# import std::process
#
# process.panic('Uh-oh, something bad happened!')
def panic(message: ToString) -> Void {
def panic(message: ToString) -> Never {
_INKOC.panic(message.to_string)
}
......@@ -223,7 +223,7 @@ object Runner {
}
# Starts the runner, blocking the calling process.
def run -> Void {
def run -> Never {
let command = process.receive as Command
command.run(@state)
......
......@@ -21,7 +21,7 @@ import std::string_buffer::StringBuffer
# import std::vm
#
# vm.exit(1)
def exit(status: Integer) -> Void {
def exit(status: Integer) -> Never {
_INKOC.exit(status)
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment