Skip to content

Commit

Permalink
Implement is_convertible_from_type for concepts
Browse files Browse the repository at this point in the history
  • Loading branch information
edubart committed Sep 29, 2020
1 parent 54c851e commit adaccde
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
7 changes: 7 additions & 0 deletions nelua/types.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ local metamagic = require 'nelua.utils.metamagic'
local bn = require 'nelua.utils.bn'
local except = require 'nelua.utils.except'
local shaper = require 'nelua.utils.shaper'
local Attr = require 'nelua.attr'
local config = require 'nelua.configer'.get()

local types = {}
Expand Down Expand Up @@ -2134,6 +2135,12 @@ function ConceptType:get_convertible_from_attr(attr, _, argattrs)
return type, err
end

-- Checks if this type is convertible from another type.
function ConceptType:is_convertible_from_type(type, explicit)
local attr = Attr{type=type}
return self:get_convertible_from_attr(attr, explicit, {attr})
end

function types.make_overload_concept(context, syms, ...)
if traits.is_symbol(syms) or traits.is_type(syms) then
syms = table.pack(syms, ...)
Expand Down
1 change: 1 addition & 0 deletions spec/03-typechecker_spec.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1487,6 +1487,7 @@ it("concepts", function()
local an_integral = #[concept(function(x)
return x.type.is_integral
end)]#
## static_assert(an_integral.value:is_convertible_from_type(primtypes.integer))
local an_integer_array = #[concept(function(x)
return x.type:is_array_of(primtypes.integer)
end)]#
Expand Down

0 comments on commit adaccde

Please sign in to comment.