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
3555
3555
not bootstrapped? ( Macro ) ->
3556
3556
nil
3557
3557
3558
- not function? and __CALLER__ . context == :match ->
3558
+ not function? and ( __CALLER__ . context == :match or __CALLER__ . context == :guard ) ->
3559
3559
raise ArgumentError ,
3560
3560
"""
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:
3562
3564
3563
3565
@foo = :value
3564
3566
Original file line number Diff line number Diff line change @@ -831,11 +831,25 @@ defmodule KernelTest do
831
831
end
832
832
833
833
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 ->
835
835
defmodule MatchAttributeInModule do
836
836
@ foo = 42
837
837
end
838
838
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
839
853
end
840
854
end
841
855
You can’t perform that action at this time.
0 commit comments