Skip to content

Commit

Permalink
cherry-pick some changes from #605
Browse files Browse the repository at this point in the history
  • Loading branch information
aviatesk committed Jan 30, 2024
1 parent 5960be0 commit 856f328
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 15 deletions.
10 changes: 4 additions & 6 deletions src/analyzers/jetanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 10 additions & 9 deletions test/analyzers/test_jetanalyzer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 856f328

Please sign in to comment.