`@assume_effects` and `@nospecializeinfer` together produce wrong result
I've encountered a situation where the result of a function call changes if both `@assume_effects :foldable` and `@nospecializeinfer` are used. Here is a MWE:
```
using Base: @assume_effects, @nospecializeinfer
@nospecializeinfer function g(T::Type{<:Tuple{Any,Any}})
@assume_effects :foldable
@nospecialize
promote_type(map(f, fieldtypes(T))...)
# promote_type(f(fieldtypes(T)[1]), f(fieldtypes(T)[2]))
end
h(t::T) where T <: Tuple{Any,Any} = g(T)
t = ('x', 'y')
T = typeof(t)
f(::Type{Char}) = Int8
@show g(T), h(t)
f(::Type{Char}) = Bool
@show g(T), h(t)
```
The output is
```
(g(T), h(t)) = (Int8, Int8)
(g(T), h(t)) = (Bool, Int8)
```
So the function `g` notices that `f` has changed, but `h` doesn't. (Or is this expected because of some world-age implications?) If `@nospecializeinfer` or `@assume_effects` is removed, then I get the expected result:
```
(g(T), h(t)) = (Int8, Int8)
(g(T), h(t)) = (Bool, Bool)
```
Also, if the call to `promote_type` is replaced by the line that is commented out, the result is again correct.
Tested with Julia 1.10.11, 1.11.9, 1.12.6 and 1.13.0-rc1.
关闭于 2026-05-29 7 条评论