diff --git a/nelua/types.lua b/nelua/types.lua index ce45ffa1..82bd6202 100644 --- a/nelua/types.lua +++ b/nelua/types.lua @@ -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 = {} @@ -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, ...) diff --git a/spec/03-typechecker_spec.lua b/spec/03-typechecker_spec.lua index 440a486c..e10adeb3 100644 --- a/spec/03-typechecker_spec.lua +++ b/spec/03-typechecker_spec.lua @@ -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)]#