aviatesk / JET.jl

An experimental code analyzer for Julia. No need for additional type annotations.
https://aviatesk.github.io/JET.jl/dev/
MIT License
735 stars 30 forks source link

Propagate conditional field type of mutable struct #478

Open Roger-luo opened 1 year ago

Roger-luo commented 1 year ago

I already checked fn.kwargs is not nothing but it seems JET still does a union split on fn.kwargs and reporting false positive on method call of nothing here

https://github.com/Roger-luo/Expronicon.jl/blob/main/src/codegen.jl#L65

reported via

JET.report_package("Expronicon")

related results

┌ @ /Users/roger/Code/Julia/Expronicon/src/codegen.jl:67 fn.kwargs[1]
│ no matching method found `getindex(::Nothing, ::Int64)` (1/2 union split): ((fn::Expronicon.JLFunction).kwargs::Union{Nothing, Vector{Any}})[1]
└────────────────────────────────────────────────────────
┌ @ /Users/roger/Code/Julia/Expronicon/src/codegen.jl:68 fn.kwargs[1]
│ no matching method found `getindex(::Nothing, ::Int64)` (1/2 union split): ((fn::Expronicon.JLFunction).kwargs::Union{Nothing, Vector{Any}})[1]
└────────────────────────────────────────────────────────
aviatesk commented 1 year ago

If you define JLFunction as immutable struct, JET should no longer report the issue. Fixing this for mutable case requires escape analysis.