From 22b5d93b2b1daf2de8f0264f818ea8e2602a5d24 Mon Sep 17 00:00:00 2001 From: Martin Holters Date: Mon, 28 Sep 2020 19:33:17 +0200 Subject: [PATCH] Fix `getfield_tfunc` for `PartialStruct` with `Vararg` (#37769) Add an `unwrapva` to ensure the returned type is not a `Vararg`. --- base/compiler/tfuncs.jl | 2 +- test/compiler/inference.jl | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/base/compiler/tfuncs.jl b/base/compiler/tfuncs.jl index 61d8dfa3b2b92..9e0cad564901f 100644 --- a/base/compiler/tfuncs.jl +++ b/base/compiler/tfuncs.jl @@ -809,7 +809,7 @@ function getfield_tfunc(@nospecialize(s00), @nospecialize(name)) nv = fieldindex(widenconst(s), nv, false) end if isa(nv, Int) && 1 <= nv <= length(s.fields) - return s.fields[nv] + return unwrapva(s.fields[nv]) end end s = widenconst(s) diff --git a/test/compiler/inference.jl b/test/compiler/inference.jl index 9f45de723acb2..b1b1ea5cf34cc 100644 --- a/test/compiler/inference.jl +++ b/test/compiler/inference.jl @@ -2838,3 +2838,6 @@ f_apply_cglobal(args...) = cglobal(args...) @test !Core.Compiler.intrinsic_nothrow(Core.bitcast, Any[Type{Ptr}, Ptr]) f37532(T, x) = (Core.bitcast(Ptr{T}, x); x) @test Base.return_types(f37532, Tuple{Any, Int}) == Any[Int] + +# issue #37638 +@test !(Core.Compiler.return_type(() -> (nothing, Any[]...)[2], Tuple{}) <: Vararg)