File tree 2 files changed +21
-0
lines changed 2 files changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -126,6 +126,9 @@ macro view(ex)
126
126
Meta. isexpr (ex, :ref ) || throw (ArgumentError (
127
127
" Invalid use of @view macro: argument must be a reference expression A[...]." ))
128
128
ex = replace_ref_begin_end! (ex)
129
+ # NOTE We embed `view` as a function object itself directly into the AST.
130
+ # By doing this, we prevent the creation of function definitions like
131
+ # `view(A, idx) = xxx` in cases such as `@view(A[idx]) = xxx.`
129
132
if Meta. isexpr (ex, :ref )
130
133
ex = Expr (:call , view, ex. args... )
131
134
elseif Meta. isexpr (ex, :let ) && (arg2 = ex. args[2 ]; Meta. isexpr (arg2, :ref ))
Original file line number Diff line number Diff line change 937
937
v = view (1 : 2 , r)
938
938
@test v == view (1 : 2 , collect (r))
939
939
end
940
+
941
+ # https://github.com/JuliaLang/julia/pull/53064
942
+ # `@view(A[idx]) = xxx` should raise syntax error always
943
+ @test try
944
+ Core. eval (@__MODULE__ , :(@view (A[idx]) = 2 ))
945
+ false
946
+ catch err
947
+ err isa ErrorException && startswith (err. msg, " syntax:" )
948
+ end
949
+ module Issue53064
950
+ import Base: view
951
+ end
952
+ @test try
953
+ Core. eval (Issue53064, :(@view (A[idx]) = 2 ))
954
+ false
955
+ catch err
956
+ err isa ErrorException && startswith (err. msg, " syntax:" )
957
+ end
You can’t perform that action at this time.
0 commit comments