diff --git a/src/compile-time.buildclass.jl b/src/compile-time.buildclass.jl index 04d7104..9d2b3e9 100644 --- a/src/compile-time.buildclass.jl +++ b/src/compile-time.buildclass.jl @@ -243,10 +243,23 @@ function codegen(cur_line :: LineNumberNode, cur_mod::Module, type_def::TypeDef) insert!(each.body.args, 1, each.ln) each.name = typename push!(struct_block, each.ln) - push!(struct_block, to_expr(each)) + + # (partially) fix issue #10: parametric constructor warning if !isempty(type_def.typePars) + if isempty(each.pars) && isempty(each.kwPars) + # although it is generally difficult to analyze + # the use of type parameters in AST level, + # for the special case that the constructor has no parameters, + # we can safely assume that the type parameters are not used + else + push!(struct_block, to_expr(each)) + end each.name = class_ann push!(struct_block, to_expr(each)) + else + # when there is no type parameters, we can safely use + # this constructor as the default one. + push!(struct_block, to_expr(each)) end custom_init = true continue diff --git a/src/compile-time.static_dispatch.jl b/src/compile-time.static_dispatch.jl index 70e96fc..37d39f5 100644 --- a/src/compile-time.static_dispatch.jl +++ b/src/compile-time.static_dispatch.jl @@ -40,7 +40,7 @@ function build_multiple_dispatch!( @warn "properties using `set_xxx` are deprecated, use '@property($name) do; set = (self, value) -> statement end' instead." _has_warn_setter_dep[] = true end - + local key = @setter_prop(name) if !haskey(method_dict, key) method_dict[key] = PropertyDefinition(name, desc.def, desc.from_type, SetterPropertyKind) diff --git a/test/runtests.jl b/test/runtests.jl index 1392a7f..398f2cf 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -369,6 +369,15 @@ module structdef end end +@testset "fix #10: parametric constructor warning" begin + @test_nowarn @eval @oodef struct Foo{F} + x::F + function new() + @mk x = F(1) + end + end +end + include("example.jl") Example.DoPrint[] = false Example.runtest()