 
   defp collect_defined_type_pairs(type_typespecs) do
     Enum.reduce(type_typespecs, %{}, fn {_, {_, expr, pos}}, type_pairs ->
-      env = :elixir_locals.get_cached_env(pos)
+      %{file: file, line: line} = env = :elixir_locals.get_cached_env(pos)
 
       case type_to_signature(expr) do
         {name, arity} = type_pair ->


  defp filter_used_types(types, state) do
    Enum.filter(types, fn {_kind, {name, arity} = type_pair, _line, _type, export} ->
      case {type_pair in state.used_type_pairs, export} do
        {false, false} ->
          env = Map.fetch!(state.defined_type_pairs, type_pair)
          :elixir_errors.warn(env.line, env.file, "type #{name}/#{arity} is unused")
          false

        _ ->
          true
      end
    end)
  end

            compile_error(env, "type #{name}/#{arity} is already defined")
          end

          Map.put(type_pairs, type_pair, {file, line})

        :error ->
          compile_error(env, "invalid type specification: #{Macro.to_string(expr)}")
