From 9de38dcf0bccb14dd1a3b03c31e0518c8bd7a135 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Mon, 20 Jul 2015 22:54:52 -0400 Subject: [PATCH] fix #8010, missing type error in new() for immutables --- src/cgutils.cpp | 9 +++------ test/core.jl | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 6 deletions(-) diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 289e20b11b5dc..00c9b1b35f9bf 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -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) diff --git a/test/core.jl b/test/core.jl index a7f8652ee5c7e..8c0ea99c7516a 100644 --- a/test/core.jl +++ b/test/core.jl @@ -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])