From 332cd2c6c03c32bd60b95757f4fc9b419033c644 Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Fri, 25 Aug 2017 10:54:04 -0400 Subject: [PATCH] fix #23430, counter overflow in subtyping Ref #23447 (cherry picked from commit 4d4b9ce06de296df3d51646c66192681ca1a8788) --- src/subtype.c | 5 +++-- test/subtype.jl | 19 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/subtype.c b/src/subtype.c index 98b44bc6d54980..b636d77bba83dd 100644 --- a/src/subtype.c +++ b/src/subtype.c @@ -420,9 +420,10 @@ static int subtype_ufirst(jl_value_t *x, jl_value_t *y, jl_stenv_t *e) static void record_var_occurrence(jl_varbinding_t *vb, jl_stenv_t *e, int param) { if (vb != NULL && param) { - if (param == 2 && e->invdepth > vb->depth0) + // saturate counters at 2; we don't need values bigger than that + if (param == 2 && e->invdepth > vb->depth0 && vb->occurs_inv < 2) vb->occurs_inv++; - else + else if (vb->occurs_cov < 2) vb->occurs_cov++; } } diff --git a/test/subtype.jl b/test/subtype.jl index 0f391208f98922..3e2fcab5d01d12 100644 --- a/test/subtype.jl +++ b/test/subtype.jl @@ -1130,3 +1130,22 @@ end @testintersect(Tuple{DataType, Any}, Tuple{Type{T}, Int} where T, Tuple{DataType, Int}) + +# issue #23430 +@test [0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; + 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; + 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; + 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; + 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; 0 0.; + 0 0.; 0 0.; 0 0.; 0 0.] isa Matrix{Float64} +@test !(Tuple{Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64, + Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64, + Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64, + Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64, + Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64, + Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64, + Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64, + Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64, + Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64, + Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64, + Int64,Float64,Int64,Float64,Int64,Float64,Int64,Float64} <: (Tuple{Vararg{T}} where T<:Number))