diff --git a/src/gf.c b/src/gf.c index 27a7d85e5a4c4..b3ef5221105e0 100644 --- a/src/gf.c +++ b/src/gf.c @@ -1276,7 +1276,15 @@ static void method_overwrite(jl_typemap_entry_t *newentry, jl_method_t *oldvalue if ((jl_options.warn_overwrite == JL_OPTIONS_WARN_OVERWRITE_ON) || (jl_options.incremental && jl_generating_output()) || anon) { JL_STREAM *s = JL_STDERR; - jl_printf(s, "WARNING: Method definition "); + ios_t memstream; + if (anon) { + ios_mem(&memstream, 300); + s = (JL_STREAM*)&memstream; + } + else { + jl_printf(s, "WARNING: "); + } + jl_printf(s, "Method definition "); jl_static_show_func_sig(s, (jl_value_t*)newentry->sig); jl_printf(s, " in module %s", jl_symbol_name(oldmod->name)); print_func_loc(s, oldvalue); @@ -1287,7 +1295,13 @@ static void method_overwrite(jl_typemap_entry_t *newentry, jl_method_t *oldvalue jl_printf(s, anon ? " on the same line" : " on the same line (check for duplicate calls to `include`)"); else print_func_loc(s, method); - jl_printf(s, ".\n"); + jl_printf(s, "."); + if (anon) { + jl_value_t *msg = jl_pchar_to_string(memstream.buf, memstream.size); + JL_GC_PUSH1(&msg); + jl_throw(jl_new_struct(jl_errorexception_type, msg)); + } + jl_printf(s, "\n"); jl_uv_flush(s); } if (jl_options.incremental && jl_generating_output()) diff --git a/test/misc.jl b/test/misc.jl index 76be4e036dd5c..2b088046add62 100644 --- a/test/misc.jl +++ b/test/misc.jl @@ -86,18 +86,25 @@ let $redir_err module A; f() = 1; end; A.f() = 1 A.f() = 1 - outer() = (g() = 1; g() = 2; g) """ warning_str = read(`$exename --warn-overwrite=yes --startup-file=no -e $script`, String) @test warning_str == """ WARNING: Method definition f() in module A at none:2 overwritten in module Main on the same line (check for duplicate calls to `include`). WARNING: Method definition f() in module Main at none:2 overwritten at none:3. - WARNING: Method definition g() in module Main at none:4 overwritten on the same line. """ warning_str = read(`$exename --startup-file=no -e $script`, String) - @test warning_str == """ - WARNING: Method definition g() in module Main at none:4 overwritten on the same line. - """ + @test warning_str == "" +end + +# Overriding closure methods is an error (#15602) +let g_line = (@__LINE__) + 3, + closure_method_overwrite = + :(function closure_method_overrwrite_g() + g() = 1 + g() = 2 + end) + @test_throws ErrorException("Method definition g() in module $(nameof(@__MODULE__)) at $(@__FILE__):$g_line overwritten at $(@__FILE__):$(g_line+1).") #= + =# eval(closure_method_overwrite) end # Debugging tool: return the current state of the enable_finalizers counter. diff --git a/test/specificity.jl b/test/specificity.jl index de65c289be02a..dc480adbee850 100644 --- a/test/specificity.jl +++ b/test/specificity.jl @@ -81,19 +81,15 @@ _bound_vararg_specificity_1(::Type{Array{T,1}}, d::Int) where {T} = 1 @test args_morespecific(Tuple{Matrix}, Tuple{AbstractVector}) # Method specificity -begin - local f, A - f(dims::Tuple{}, A::AbstractArray{T,0}) where {T} = 1 - f(dims::NTuple{N,Int}, A::AbstractArray{T,N}) where {T,N} = 2 - f(dims::NTuple{M,Int}, A::AbstractArray{T,N}) where {T,M,N} = 3 - A = zeros(2,2) - @test f((1,2,3), A) == 3 - @test f((1,2), A) == 2 - @test f((), reshape([1])) == 1 - f(dims::NTuple{N,Int}, A::AbstractArray{T,N}) where {T,N} = 4 - @test f((1,2), A) == 4 - @test f((1,2,3), A) == 3 -end +f22162(dims::Tuple{}, A::AbstractArray{T,0}) where {T} = 1 +f22162(dims::NTuple{N,Int}, A::AbstractArray{T,N}) where {T,N} = 2 +f22162(dims::NTuple{M,Int}, A::AbstractArray{T,N}) where {T,M,N} = 3 +@test f22162((1,2,3), zeros(2,2)) == 3 +@test f22162((1,2), zeros(2,2)) == 2 +@test f22162((), reshape([1])) == 1 +f22162(dims::NTuple{N,Int}, A::AbstractArray{T,N}) where {T,N} = 4 +@test f22162((1,2), zeros(2,2)) == 4 +@test f22162((1,2,3), zeros(2,2)) == 3 # a method specificity issue c99991(::Type{T},x::T) where {T} = 0 diff --git a/test/tuple.jl b/test/tuple.jl index 768a1050c09c0..5e5b379ade085 100644 --- a/test/tuple.jl +++ b/test/tuple.jl @@ -607,9 +607,9 @@ f38837(xs) = map((F,x)->F(x), (Float32, Float64), xs) @test @inferred(f(Tuple(1:10))) === Tuple(3:8) @test @inferred(f((true, 2., 3, 4f0, 0x05, 6, 7.))) === (3, 4f0, 0x05) - f(t) = t[Base.OneTo(5)] - @test @inferred(f(Tuple(1:10))) === Tuple(1:5) - @test @inferred(f((true, 2., 3, 4f0, 0x05, 6, 7.))) === (true, 2., 3, 4f0, 0x05) + g(t) = t[Base.OneTo(5)] + @test @inferred(g(Tuple(1:10))) === Tuple(1:5) + @test @inferred(g((true, 2., 3, 4f0, 0x05, 6, 7.))) === (true, 2., 3, 4f0, 0x05) @test @inferred((t -> t[1:end])(Tuple(1:15))) === Tuple(1:15) @test @inferred((t -> t[2:end])(Tuple(1:15))) === Tuple(2:15)