Skip to content

Commit

Permalink
fix #8010, missing type error in new() for immutables
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffBezanson committed Jul 21, 2015
1 parent 298231e commit 9de38dc
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
9 changes: 3 additions & 6 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2044,17 +2044,14 @@ static Value *emit_new_struct(jl_value_t *ty, size_t nargs, jl_value_t **args, j
if (jl_isbits(sty)) {
Type *lt = julia_type_to_llvm(ty);
size_t na = nargs-1 < nf ? nargs-1 : nf;
if (lt == T_void) {
for (size_t i=0; i < na; i++)
emit_unboxed(args[i+1], ctx); // do side effects
return mark_julia_type(UndefValue::get(NoopType),ty);
}
Value *strct = UndefValue::get(lt);
Value *strct = UndefValue::get(lt == T_void ? NoopType : lt);
unsigned idx = 0;
for (size_t i=0; i < na; i++) {
jl_value_t *jtype = jl_svecref(sty->types,i);
Type *fty = julia_type_to_llvm(jtype);
Value *fval = emit_unboxed(args[i+1], ctx);
if (!jl_subtype(expr_type(args[i+1],ctx), jtype, 0))
emit_typecheck(fval, jtype, "new", ctx);
if (!type_is_ghost(fty)) {
fval = emit_unbox(fty, fval, jtype);
if (fty == T_int1)
Expand Down
17 changes: 17 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3138,3 +3138,20 @@ function Sampler11587()
Sampler11587(zeros(Int,a), zeros(Float64,a))
end
@test isa(Sampler11587(), Sampler11587{2})

# issue #8010 - error when convert returns wrong type during new()
immutable Vec8010{T}
x::T
y::T
end
Vec8010(a::AbstractVector) = Vec8010(ntuple(x->a[x],2)...)
Base.convert{T}(::Type{Vec8010{T}},x::AbstractVector) = Vec8010(x)
Base.convert(::Type{Void},x::AbstractVector) = Vec8010(x)
immutable MyType8010
m::Vec8010{Float32}
end
immutable MyType8010_ghost
m::Void
end
@test_throws TypeError MyType8010([3.0;4.0])
@test_throws TypeError MyType8010_ghost([3.0;4.0])

0 comments on commit 9de38dc

Please sign in to comment.