Skip to content

Commit

Permalink
fix #10 when no parameters are given (#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
thautwarm authored Jan 31, 2024
1 parent 1de9ba0 commit e5a9a3f
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 2 deletions.
15 changes: 14 additions & 1 deletion src/compile-time.buildclass.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/compile-time.static_dispatch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit e5a9a3f

Please sign in to comment.