When locking a non-concrete type to a global, it may be reasonable to allow narrowing the locked type to a subtype.
Consider:
julia> s::Number = 3
3
julia> s::Int64 = 5
ERROR: cannot set type for global Main.s. It already has a value or is already set to a different type.
Stacktrace:
[1] top-level scope
@ REPL[4]:1
julia> s = 1.2
1.2
The suggestion is to allow s::Int64 = 5
to proceed without error and lock s
into Int64
. In this case, the last s = 1.2
would error.
In this way, a global
t = 5
can be essentially the same as:
t::Any = 5
which might be a nice way to think of unlocked globals.
(coded in Julia 1.10)
There may be issues about recompilations needed (if loosely locked globals are narrowed), but that may be a price to pay for allowing interactive development with untyped globals and then getting the speed of typed globals without leaving the REPL.
Anyway, raising this idea to hear the problems with it…