Skip to content

Commit

Permalink
Rename type assertion to type cast
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Aug 15, 2020
1 parent 47ca24b commit 1361a00
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 10 deletions.
12 changes: 6 additions & 6 deletions nelua/analyzer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -860,14 +860,14 @@ local function izipargnodes(vars, argnodes)
end
end

local function visitor_Call_typeassertion(context, node, argnodes, type)
local function visitor_Call_type_cast(context, node, argnodes, type)
local attr = node.attr
assert(type)
if type.is_generic then
node:raisef("type assertion to generic '%s': cannot do assertion on generics", type)
node:raisef("type cast to generic '%s': cannot do type cast on generics", type)
end
if #argnodes > 1 then
node:raisef("type assertion to type '%s': expected at most 1 argument, but got %d",
node:raisef("type cast to type '%s': expected at most 1 argument, but got %d",
type, #argnodes)
end
local argnode = argnodes[1]
Expand All @@ -880,7 +880,7 @@ local function visitor_Call_typeassertion(context, node, argnodes, type)
if argtype then
local ok, err = type:is_convertible_from_attr(argattr, true)
if not ok then
argnode:raisef("in type assertion: %s", err)
argnode:raisef("in type cast: %s", err)
end
if argattr.comptime then
attr.value = type:normalize_value(argattr.value)
Expand All @@ -894,7 +894,7 @@ local function visitor_Call_typeassertion(context, node, argnodes, type)
done = nil
end
end
attr.typeassertion = true
attr.typecast = true
attr.type = type
attr.calleetype = primtypes.type
node.done = done
Expand Down Expand Up @@ -1063,7 +1063,7 @@ function visitors.Call(context, node)
end

if calleetype and calleetype.is_type then
visitor_Call_typeassertion(context, node, argnodes, calleeattr.value)
visitor_Call_type_cast(context, node, argnodes, calleeattr.value)
else
visitor_Call(context, node, argnodes, calleetype, calleesym)

Expand Down
2 changes: 1 addition & 1 deletion nelua/cgenerator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -688,7 +688,7 @@ function visitors.Call(context, node, emitter)
callee = builtin(context, node, emitter)
end
if calleetype.is_type then
-- type assertion
-- type cast
local type = node.attr.type
if #argnodes == 1 then
local argnode = argnodes[1]
Expand Down
2 changes: 1 addition & 1 deletion spec/02-syntaxdefs_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1521,7 +1521,7 @@ describe("type expression", function()
{ n.TypeInstance{n.RecordType{{n.RecordFieldType{'a', n.Type{'integer'}}}}}}
}}})
end)
it("type assertion", function()
it("type cast", function()
assert.parse_ast(nelua_parser, "local a = (@integer)(0)",
n.Block{{
n.VarDecl{'local',
Expand Down
2 changes: 1 addition & 1 deletion spec/03-typechecker_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1523,7 +1523,7 @@ it("generics", function()
assert.analyze_error([[
local myarray = #[generic(function() end)]#
local x = myarray(integer)
]], "cannot do assertion on generics")
]], "cannot do type cast on generics")
assert.analyze_error([[
local myarray = #[generic(function() end)]#
local x = @myarray(integer)
Expand Down
2 changes: 1 addition & 1 deletion spec/05-cgenerator_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ it("number literals", function()
assert.generate_c("local a = ' '_cuchar", "unsigned char a = 32U;")
end)

it("type assertion", function()
it("type cast", function()
assert.generate_c("do local b = 1_u64; local a = (@int16)(b) end", "int16_t a = (int16_t)b")
assert.generate_c("do local b = 1_u8; local a = (@int64)(b) end", "int64_t a = (int64_t)b")
assert.generate_c([[
Expand Down

0 comments on commit 1361a00

Please sign in to comment.