Skip to content

Commit 00a0f07

Browse files
eksperimentaljosevalim
authored andcommitted
Allow Application.compile_env* to accept attributes (#11383)
1 parent c28073b commit 00a0f07

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

lib/elixir/lib/application.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -508,7 +508,7 @@ defmodule Application do
508508
# compile time instead of compile_env
509509
@doc since: "1.10.0"
510510
@spec compile_env(app, key | list, value) :: value
511-
defmacro compile_env(app, key_or_path, default \\ nil) when is_atom(app) do
511+
defmacro compile_env(app, key_or_path, default \\ nil) do
512512
if __CALLER__.function do
513513
raise "Application.compile_env/3 cannot be called inside functions, only in the module body"
514514
end
@@ -545,7 +545,7 @@ defmodule Application do
545545
"""
546546
@doc since: "1.10.0"
547547
@spec compile_env!(app, key | list) :: value
548-
defmacro compile_env!(app, key_or_path) when is_atom(app) do
548+
defmacro compile_env!(app, key_or_path) do
549549
if __CALLER__.function do
550550
raise "Application.compile_env!/2 cannot be called inside functions, only in the module body"
551551
end

lib/elixir/test/elixir/application_test.exs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ defmodule ApplicationTest do
66
import PathHelpers
77
import ExUnit.CaptureIO
88

9+
@app :elixir
10+
911
test "application environment" do
1012
assert_raise ArgumentError, ~r/because the application was not loaded nor configured/, fn ->
1113
Application.fetch_env!(:unknown, :unknown)
@@ -75,12 +77,14 @@ defmodule ApplicationTest do
7577

7678
assert Application.put_env(:elixir, :unknown, nested: [key: :value]) == :ok
7779

80+
assert compile_env(@app, :unknown, :default) == [nested: [key: :value]]
7881
assert compile_env(:elixir, :unknown, :default) == [nested: [key: :value]]
7982
assert_received {:compile_env, :elixir, [:unknown], {:ok, [nested: [key: :value]]}}
8083

8184
assert compile_env(:elixir, :unknown) == [nested: [key: :value]]
8285
assert_received {:compile_env, :elixir, [:unknown], {:ok, [nested: [key: :value]]}}
8386

87+
assert compile_env!(@app, :unknown) == [nested: [key: :value]]
8488
assert compile_env!(:elixir, :unknown) == [nested: [key: :value]]
8589
assert_received {:compile_env, :elixir, [:unknown], {:ok, [nested: [key: :value]]}}
8690

0 commit comments

Comments
 (0)