@@ -287,7 +287,7 @@ defmodule Module.Types.Infer do
287287 end
288288
289289 @ doc """
290- Adds a variable to the typing context and returns its type variables .
290+ Adds a variable to the typing context and returns its type variable .
291291 If the variable has already been added, return the existing type variable.
292292 """
293293 def new_var ( var , context ) do
@@ -315,6 +315,11 @@ defmodule Module.Types.Infer do
315315 end
316316 end
317317
318+ @ doc """
319+ Adds an internal variable to the typing context and returns its type variable.
320+ An internal variable is used to help unify complex expressions,
321+ it does not belong to a specific AST expression.
322+ """
318323 def add_var ( context ) do
319324 type = { :var , context . counter }
320325 types = Map . put ( context . types , context . counter , :unbound )
@@ -543,13 +548,11 @@ defmodule Module.Types.Infer do
543548 # Tag if trace is for a concrete type or type variable
544549 defp tag_traces ( traces , context ) do
545550 Enum . flat_map ( traces , fn { var , { type , expr , location } } ->
546- case type do
547- { :var , var_index } ->
548- var2 = Map . fetch! ( context . types_to_vars , var_index )
549- [ { var , { :var , var2 , expr , location } } ]
550-
551- _ ->
552- [ { var , { :type , type , expr , location } } ]
551+ with { :var , var_index } <- type ,
552+ % { ^ var_index => expr_var } <- context . types_to_vars do
553+ [ { var , { :var , expr_var , expr , location } } ]
554+ else
555+ _ -> [ { var , { :type , type , expr , location } } ]
553556 end
554557 end )
555558 end
0 commit comments