File tree Expand file tree Collapse file tree 2 files changed +19
-3
lines changed
Expand file tree Collapse file tree 2 files changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -3555,10 +3555,12 @@ defmodule Kernel do
35553555 not bootstrapped? ( Macro ) ->
35563556 nil
35573557
3558- not function? and __CALLER__ . context == :match ->
3558+ not function? and ( __CALLER__ . context == :match or __CALLER__ . context == :guard ) ->
35593559 raise ArgumentError ,
35603560 """
3561- invalid write attribute syntax. If you want to define an attribute, don't do this:
3561+ invalid usage of module attributes. Module attributes cannot be used inside \
3562+ pattern matching (and guards) outside of a function. If you are trying to \
3563+ define an attribute, do not do this:
35623564
35633565 @foo = :value
35643566
Original file line number Diff line number Diff line change @@ -831,11 +831,25 @@ defmodule KernelTest do
831831 end
832832
833833 test "matching attribute" do
834- assert_raise ArgumentError , ~r" invalid write attribute syntax " , fn ->
834+ assert_raise ArgumentError , ~r" invalid usage of module attributes " , fn ->
835835 defmodule MatchAttributeInModule do
836836 @ foo = 42
837837 end
838838 end
839+
840+ assert_raise ArgumentError , ~r" invalid usage of module attributes" , fn ->
841+ defmodule MatchAttributeInModule do
842+ @ foo 16
843+ << _ :: @ foo >> = "ab"
844+ end
845+ end
846+
847+ assert_raise ArgumentError , ~r" invalid usage of module attributes" , fn ->
848+ defmodule MatchAttributeInModule do
849+ @ foo 16
850+ << _ :: size ( @ foo ) >> = "ab"
851+ end
852+ end
839853 end
840854 end
841855
You can’t perform that action at this time.
0 commit comments