Commit Graph
8196 Commits
Author SHA1 Message Date
kw7oe f44adfbeb0 Improve heredoc error message (#9048) 2019-05-19 10:10:11 +02:00
José Valim 2d1fe10e3d Update CHANGELOG 2019-05-18 22:17:19 +02:00
Andrea Leopardi 39c6eb64fe Mention default return in List.keyfind/4 docs
[ci skip]
2019-05-18 19:02:46 +02:00
Aleksei Magusev 7bdffe148f Remove unnecessary is_reference/1 check 2019-05-17 02:06:07 +02:00
José Valim 10fd316439 Delegate Erlang/OTP version check to Elixir 2019-05-15 17:23:26 +02:00
mguimas d63a7a46a7 Support default value when reading inexistent module attribute (#9041)
The private function Module.put_attribute/4 has been renamed to
Module.__put_attribute__/4 for consistency.
2019-05-15 09:28:35 +02:00
Eksperimental c8e700bec1 Improve List.duplicate/2 (#9044) 2019-05-15 09:17:10 +02:00
Eksperimental 341a2d1da8 Improve List.flatten/1,2 (#9045) 2019-05-15 09:16:31 +02:00
Eksperimental 30ab4ad968 Revert #8777 (#9042)
Revert "Remove Integer.to_string/1 and Integer.to_charlist/1 (#8777)"

This reverts commit 2622fd6b0a.
2019-05-15 09:15:55 +02:00
Eksperimental 3038401b09 Improve List.delete/2 (#9043) 2019-05-15 09:14:38 +02:00
José Valim 161f5f9a3b Add Erlang/OTP 22 compatible versions 2019-05-14 14:50:44 +02:00
José Valim 921738899b Escape Unicode chars in String, closes #9039 2019-05-11 09:23:48 +02:00
Victor Rodrigues 7e6bac3450 Do not allow defmodule with special atoms (#9032)
Fixes #9030
2019-05-10 20:47:36 +02:00
José Valim 0229358f88 Ensure third element in location tuple is either nil or an integer 2019-05-09 10:59:13 +02:00
José Valim 81e5a57d51 Nest all terminator metadata under :end key 2019-05-09 10:28:18 +02:00
José Valim dc154f5db7 Allow developers to choose between sname and name in releases (#9024)
We default to --sname which provides safer security defaults.
2019-05-08 11:14:28 +02:00
José Valim 7cd6ce4a32 Also provide nice error message on null bytes 2019-05-06 16:37:54 +02:00
Wojtek Mach 6fae20977e Document Inspect.inspect/2 (#9015) 2019-05-06 16:36:46 +02:00
Andrea Leopardi ad4a11da74 Use parens in IO.puts/1 calls around the codebase (#9018)
There were instances of IO.puts/1 calls without parens throughout the
 whole codebase (in docs, code, tests). I removed most of them where it
made sense to do so, so that users will find documentation and other
things consistent with how the formatter behaves.
2019-05-06 10:30:42 +02:00
Tony Han e38cd472d9 Fix a syntax error in the docs for try/1 (#9017)
[ci skip]
2019-05-06 10:02:30 +02:00
José Valim 6ac1b99e0c Rely on bootstrap only during compilation 2019-05-04 16:43:18 +02:00
Wojtek Mach 9a75975769 Add inspect_fun to Inspect.Opts (#8980)
Let's see some use cases. First we configure IEx to use our custom
function:

    iex> IEx.configure(inspect: [inspect_fun: &Pretty.inspect/2])
    :ok

1. Pretty-printing integers

    iex> :math.pow(2, 32) |> trunc()
    4_294_967_296

2. Inspect tuples as records

    iex> {:foo, :bar}
    {:foo, :bar}

    iex> {:person, "Alice", 30}
    #person(name: "Alice", age: 30)

3. Overwrite struct's Inspect implementation

    iex> URI.parse("https://elixir-lang.org")
    #URI<https://elixir-lang.org>

---

Code for the `Pretty.inspect/2` function:

    defmodule Pretty do
      def inspect(integer, opts) when is_integer(integer) do
        PrettyIntegers.inspect(integer, opts)
      end

      def inspect(tuple, opts) when is_tuple(tuple) do
        records = %{
          {:person, 2} => [:name, :age]
        }

        PrettyTuples.inspect(tuple, records, opts)
      end

      def inspect(%URI{} = uri, _opts) do
        Inspect.Algebra.concat(["#URI<", URI.to_string(uri), ">"])
      end

      def inspect(term, opts) do
        Inspect.inspect(term, opts)
      end
    end

    defmodule PrettyIntegers do
      def inspect(term, %Inspect.Opts{base: :decimal}) do
        pretty_decimal(term, "_")
      end

      def inspect(term, %Inspect.Opts{base: base}) do
        Integer.to_string(term, base_to_value(base))
        |> prepend_prefix(base)
      end

      def pretty_decimal(n, separator) when n < 0 do
        "-" <> pretty_decimal(abs(n), separator)
      end

      def pretty_decimal(n, separator) when n >= 1000 do
        left = div(n, 1_000)
        right = rem(n, 1_000)
        right_str = :io_lib.format("~3..0B", [right]) |> IO.iodata_to_binary
        pretty_decimal(left, separator) <> separator <> right_str
      end

      def pretty_decimal(n, _) do
        Integer.to_string(n)
      end

      defp base_to_value(base) do
        case base do
          :binary  -> 2
          :octal   -> 8
          :hex     -> 16
        end
      end

      defp prepend_prefix(value, base) do
        prefix = case base do
          :binary -> "0b"
          :octal  -> "0o"
          :hex    -> "0x"
        end
        prefix <> value
      end
    end

    defmodule PrettyTuples do
      import Inspect.Algebra

      def inspect({}, _records, opts), do: inspect_tuple([], opts)

      def inspect(tuple, records, opts) do
        list = Tuple.to_list(tuple)
        [record_name | values] = list

        case record_fields(records, record_name, tuple) do
          {:ok, fields} ->
            inspect_record(record_name, fields, values, opts)

          _ ->
            inspect_tuple(list, opts)
        end
      end

      defp record_fields(records, record_name, tuple) do
        fields_size = tuple_size(tuple) - 1
        Map.fetch(records, {record_name, fields_size})
      end

      defp inspect_tuple(list, opts) do
        inspect("{", list, "}", &to_doc/2, :flex, opts)
      end

      defp inspect_record(record_name, fields, values, opts) do
        kwlist = Enum.zip(fields, values)
        inspect("##{record_name}(", kwlist, ")", &Inspect.List.keyword/2, :strict, opts)
      end

      defp inspect(open, list, close, fun, break, opts) do
        open = color(open, :tuple, opts)
        sep = color(",", :tuple, opts)
        close = color(close, :tuple, opts)
        container_opts = [separator: sep, break: break]
        container_doc(open, list, close, opts, fun, container_opts)
      end
    end
2019-05-03 17:42:58 +02:00
Matthijs Kuiper 8a7817ecdb Add docs example for Path.dirname/1 when path is a filename (#9013) 2019-05-03 16:49:52 +02:00
José Valim 141915625d Consider @file attribute on undefined locals, closes #9005 2019-05-02 20:20:21 +02:00
José Valim 7f41fa903b Only linify if keep was given 2019-05-02 18:57:44 +02:00
José Valim 91f9321fcb Improve docs and use relative paths 2019-05-02 17:03:02 +02:00
José Valim 59fcce0b92 Unify error handling and compiler deadlock checking (#9009) 2019-05-02 16:27:13 +02:00
Billy Ceskavich a7b19052e8 Add defmodule/2 to default locals_without_parens list (#9007) 2019-05-02 09:54:54 +02:00
José Valim fe999119cd Update kernel.ex 2019-05-01 09:33:02 +02:00
José Valim 119b03b472 Update Library Guidelines.md 2019-04-30 18:36:15 +02:00
José Valim 89216bbe06 Do not raise on deadlock on ensure_compiled 2019-04-30 12:52:56 +02:00
Tommaso Pavese 4925c210c5 Improve the documentation and example for the Config.Provider module. (#9000) 2019-04-30 10:33:05 +02:00
Andrea Leopardi b3fb4bd7f7 Deprecate Enumerable keys in Map.{take|drop|split} (#8999)
"Keyword.{take|drop|split}" don't offer support for an Enumerable of
keys to take/drop/split based on. However, the "Map" counterparts do.
With this commit, we hard-deprecate support for Enumerables of keys in
"Map.{take|drop|split}". Only lists of keys are allowed.
2019-04-30 09:58:07 +02:00
Tomáš Janoušek 8d079862dc Fix columns in tokenize of dot_call_op (#8995)
handle_dot already gets the column of `(` from strip_dot_space.
2019-04-29 23:34:08 +02:00
Samar Dhwoj Acharya e466c357e0 Fix typo OPT -> OTP on elixir application.ex (#8996) 2019-04-29 21:53:06 +02:00
Andrea Leopardi a27c8da434 Add missing guards to functions in Keyword (#8992) 2019-04-29 10:16:18 +02:00
José Valim f10a6ea618 Clarify root node only expansion in Macro 2019-04-27 10:34:20 +02:00
Marco Milanesi 27c1e5cc19 Be more descriptive in trim functions (#8983) 2019-04-26 08:44:17 +02:00
Eric Meadows-Jönsson 0abf5b437a Document time complexity (#8981) 2019-04-25 20:49:57 +02:00
José Valim 07937fcbfd Remove complexity mention in intersperse
The overall complexity rules is detailed in the module docs.
2019-04-25 12:01:19 +02:00
José Valim 44fae5cc7a Support :force_do_end_blocks in formatter (#8978) 2019-04-24 09:27:59 +02:00
Frank Hunleth 649339aa95 Fix ETS leak in Registry.register
This fixes an issue where a registry's PIDPartition table would gain an
entry each time after the first call to Registry.register on a unique
registry.

We also guarantee unregistered works generally with "tricky keys".

Closes #8611.

Signed-off-by: José Valim <jose.valim@plataformatec.com.br>
2019-04-23 12:34:51 +02:00
Johanna Larsson e261b42413 Add Registry.select/2 (#8963) 2019-04-22 17:43:07 +02:00
José Valim 459319fb75 Improve warning for duplicate behaviours, closes #8965 2019-04-19 12:52:24 +02:00
Qqwy / Wiebe-Marten 6d5e49c120 Updates documentation of capture operator with reference to Function.capture/3 (#8964) 2019-04-18 20:33:50 +02:00
José Valim 92c76c7e7a Improve docs and since annotations 2019-04-18 20:32:43 +02:00
Fernando Tapia Rico 075339a342 Optimize &super/arity and &super(&1) (#8962)
The previous implementation was generating an unnecessary
intermediate function when using `&super/arity`.

In addition, capture expressions using `super` with sequential
value placeholders (`&n`) were not optimized like other functions.
For example, the capture expression `&foo(&1, &2, &3)` is
optimized to `&foo/3` because the value placeholders (`&n`) are
sequential `&1, &2, &3`.
2019-04-18 19:22:04 +02:00
José Valim 8faa40ebff Add config providers (#8957) 2019-04-18 16:34:50 +02:00
Nikola Jichev b007282566 Fix GenServer.code_change/3 @spec (#8959)
As we can see at http://erlang.org/doc/man/gen_server.html#Module:code_change-3,
the function returns "{:ok, new_state} | {:error, reason}" while the
old version can either be old version or "{:down, current version}".
2019-04-16 17:18:08 +02:00
Arjan Scherpenisse cef19c9365 Implement static_atom_encoder tokenizer option (#8956) 2019-04-14 19:44:17 +02:00