From 856f328256f2fd6614f6ec7d3ef46fad5b6b976f Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Tue, 30 Jan 2024 20:48:12 +0900 Subject: [PATCH] cherry-pick some changes from #605 --- src/analyzers/jetanalyzer.jl | 10 ++++------ test/analyzers/test_jetanalyzer.jl | 19 ++++++++++--------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/analyzers/jetanalyzer.jl b/src/analyzers/jetanalyzer.jl index 7795392d1..463bfbd5e 100644 --- a/src/analyzers/jetanalyzer.jl +++ b/src/analyzers/jetanalyzer.jl @@ -1297,13 +1297,11 @@ function report_fieldaccess!(analyzer::JETAnalyzer, sv::InferenceState, @nospeci end end fidx = _getfield_fieldindex(s, name) - fidx === nothing && @goto report_nofield_error - ftypes = Base.datatype_fieldtypes(s) - nf = length(ftypes) - (fidx < 1 || fidx > nf) && @goto report_nofield_error - return false + if fidx !== nothing + nf = length(Base.datatype_fieldtypes(s)) + 1 ≤ fidx ≤ nf && return false + end - @label report_nofield_error namev = (name::Const).val objtyp = s00 if namev isa Symbol diff --git a/test/analyzers/test_jetanalyzer.jl b/test/analyzers/test_jetanalyzer.jl index d83642ac6..00fdb08f8 100644 --- a/test/analyzers/test_jetanalyzer.jl +++ b/test/analyzers/test_jetanalyzer.jl @@ -701,15 +701,16 @@ access_field(x::InvalidBuiltinStruct, sym) = getfield(x, sym) end @testset "constant propagation" begin - result = report_call(x::InvalidBuiltinStruct->access_field(x,:v)) - @test isempty(get_reports_with_test(result)) - - result = report_call(x::InvalidBuiltinStruct->access_field(x,:w)) - report = only(get_reports_with_test(result)) - @test report isa BuiltinErrorReport && report.f === getfield - - result = report_call(x::InvalidBuiltinStruct->access_field(x,:v)) - @test isempty(get_reports_with_test(result)) + let result = report_call(x::InvalidBuiltinStruct->access_field(x,:v)) + @test isempty(get_reports_with_test(result)) + end + let result = report_call(x::InvalidBuiltinStruct->access_field(x,:w)) + report = only(get_reports_with_test(result)) + @test report isa BuiltinErrorReport && report.f === getfield + end + let result = report_call(x::InvalidBuiltinStruct->access_field(x,:v)) + @test isempty(get_reports_with_test(result)) + end end end