From ea59fe1c8974bac53d763df53e7d5b384ab9502c Mon Sep 17 00:00:00 2001 From: Jakob Nybo Nissen Date: Wed, 19 Oct 2022 16:39:30 +0200 Subject: [PATCH] Test that internal constructor return type asserts are respected On Julia 1.8, if the internal constructor's return value was typeasserted, this assertion could be violated without an error. For example, in this case: ```julia struct Foo x::Int Foo()::Nothing = new(1) end ``` Running `Foo()` would not throw. This was inadvertently fixed in a later PR, but not tested. This PR adds a test case similar to the example above. --- test/core.jl | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/test/core.jl b/test/core.jl index 77f46f35a0259..195241e824e0a 100644 --- a/test/core.jl +++ b/test/core.jl @@ -4859,6 +4859,13 @@ let a = Any[] @test a == [10, 2] end +# issue 47209 +struct f47209 + x::Int + f47209()::Nothing = new(1) +end +@test_throws MethodError f47209() + # issue #12096 let a = Val{Val{TypeVar(:_, Int)}}, b = Val{Val{x} where x<:Int}