@@ -37,11 +37,11 @@ function infer_type_assignment_rhs(binding, state, scope)
3737 lhs = binding. val. args[1 ]
3838 rhs = binding. val. args[2 ]
3939 if is_loop_iter_assignment (binding. val)
40- settype! (binding, infer_eltype (rhs))
40+ settype! (binding, infer_eltype (rhs, state ))
4141 elseif headof (rhs) === :ref && length (rhs. args) > 1
4242 ref = refof_maybe_getfield (rhs. args[1 ])
4343 if ref isa Binding && ref. val isa EXPR
44- settype! (binding, infer_eltype (ref. val))
44+ settype! (binding, infer_eltype (ref. val, state ))
4545 end
4646 else
4747 if CSTParser. is_func_call (rhs)
@@ -147,11 +147,20 @@ function infer_type_decl(binding, state, scope)
147147 else
148148 settype! (binding, refof (t))
149149 end
150- elseif refof (t) isa SymbolServer. DataTypeStore
151- settype! (binding, refof (t))
150+ else
151+ edt = get_eventual_datatype (refof (t), state. server. external_env)
152+ if edt != = nothing
153+ settype! (binding, edt)
154+ end
152155 end
153156end
154157
158+ get_eventual_datatype (_, _:: ExternalEnv ) = nothing
159+ get_eventual_datatype (b:: SymbolServer.DataTypeStore , _:: ExternalEnv ) = b
160+ function get_eventual_datatype (b:: SymbolServer.FunctionStore , env:: ExternalEnv )
161+ return SymbolServer. _lookup (b. extends, getsymbols (env))
162+ end
163+
155164# Work out what type a bound variable has by functions that are called on it.
156165function infer_type_by_use (b:: Binding , env:: ExternalEnv )
157166 b. type != = nothing && return # b already has a type
@@ -284,19 +293,22 @@ end
284293# Assumes x.head.val == "="
285294is_loop_iter_assignment (x:: EXPR ) = x. parent isa EXPR && ((x. parent. head == :for || x. parent. head == :generator ) || (x. parent. head == :block && x. parent. parent isa EXPR && (x. parent. parent. head == :for || x. parent. parent. head == :generator )))
286295
287- function infer_eltype (x:: EXPR )
296+ function infer_eltype (x:: EXPR , state )
288297 if isidentifier (x) && hasref (x) # assume is IDENT
289298 r = refof (x)
290299 if r isa Binding && r. val isa EXPR
291300 if isassignment (r. val) && r. val. args[2 ] != x
292- return infer_eltype (r. val. args[2 ])
301+ return infer_eltype (r. val. args[2 ], state )
293302 end
294303 end
295304 elseif headof (x) === :ref && hasref (x. args[1 ])
296305 r = refof (x. args[1 ])
297- if r isa SymbolServer. DataTypeStore ||
298- r isa Binding && CoreTypes. isdatatype (r. type)
299- r
306+ if r isa Binding && CoreTypes. isdatatype (r. type)
307+ return r
308+ end
309+ edt = get_eventual_datatype (r, state. server. external_env)
310+ if edt isa SymbolServer. DataTypeStore
311+ return edt
300312 end
301313 elseif headof (x) === :STRING
302314 return CoreTypes. Char
0 commit comments