diff --git a/src/jltypes.c b/src/jltypes.c index cf6d9b607132f..5941052e6a420 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -964,7 +964,8 @@ jl_value_t *jl_apply_type(jl_value_t *tc, jl_value_t **params, size_t n) } // if this is a wrapper, let check_datatype_parameters give the error if (!iswrapper) - jl_type_error_rt("Type", jl_symbol_name(ua->var->name), (jl_value_t*)ua->var, pi); + jl_type_error_rt(jl_is_datatype(inner) ? jl_symbol_name(inner->name->name) : "Type", + jl_symbol_name(ua->var->name), (jl_value_t*)ua->var, pi); } tc = jl_instantiate_unionall(ua, pi); @@ -1217,16 +1218,19 @@ static void check_datatype_parameters(jl_typename_t *tn, jl_value_t **params, si } assert(i == np*2); wrapper = tn->wrapper; - for(i=0; i < np; i++) { + for (i = 0; i < np; i++) { assert(jl_is_unionall(wrapper)); jl_tvar_t *tv = ((jl_unionall_t*)wrapper)->var; if (!within_typevar(params[i], bounds[2*i], bounds[2*i+1])) { - // TODO: pass a new version of `tv` containing the instantiated bounds + if (tv->lb != bounds[2*i] || tv->ub != bounds[2*i+1]) + // pass a new version of `tv` containing the instantiated bounds + tv = jl_new_typevar(tv->name, bounds[2*i], bounds[2*i+1]); + JL_GC_PUSH1(&tv); jl_type_error_rt(jl_symbol_name(tn->name), jl_symbol_name(tv->name), (jl_value_t*)tv, params[i]); } int j; - for(j=2*i+2; j < 2*np; j++) { - jl_value_t*bj = bounds[j]; + for (j = 2*i + 2; j < 2*np; j++) { + jl_value_t *bj = bounds[j]; if (bj != (jl_value_t*)jl_any_type && bj != jl_bottom_type) bounds[j] = jl_substitute_var(bj, tv, params[i]); } diff --git a/test/errorshow.jl b/test/errorshow.jl index 80ad770de6f1e..95095b1314326 100644 --- a/test/errorshow.jl +++ b/test/errorshow.jl @@ -276,7 +276,7 @@ let @test occursin("column vector", err_str) end -struct TypeWithIntParam{T <: Integer} end +struct TypeWithIntParam{T<:Integer, Vector{T}<:A<:AbstractArray{T}} end struct Bounded # not an AbstractArray bound::Int end @@ -322,8 +322,14 @@ let undefvar @test err_str == "TypeError: in Type, in parameter, expected Type, got a value of type String" err_str = @except_str TypeWithIntParam{Any} TypeError @test err_str == "TypeError: in TypeWithIntParam, in T, expected T<:Integer, got Type{Any}" + err_str = @except_str TypeWithIntParam{Int64,Vector{Float64}} TypeError + @test err_str == "TypeError: in TypeWithIntParam, in A, expected Vector{Int64}<:A<:(AbstractArray{Int64}), got Type{Vector{Float64}}" + err_str = @except_str TypeWithIntParam{Int64}{Vector{Float64}} TypeError + @test err_str == "TypeError: in TypeWithIntParam, in A, expected Vector{Int64}<:A<:(AbstractArray{Int64}), got Type{Vector{Float64}}" err_str = @except_str Type{Vararg} TypeError @test err_str == "TypeError: in Type, in parameter, expected Type, got Vararg" + err_str = @except_str Ref{Vararg} TypeError + @test err_str == "TypeError: in Type, in parameter, expected Type, got Vararg" err_str = @except_str mod(1,0) DivideError @test err_str == "DivideError: integer division error"