@@ -808,6 +808,10 @@ defmodule Macro do
808808 nodes. Note this option changes the semantics of escaped code and
809809 it should only be used when escaping ASTs. Defaults to `false`.
810810
811+ * `:generated` - (since v1.19.0) Whether the AST should be considered as generated
812+ by the compiler or not. This means the compiler and tools like Dialyzer may not
813+ emit certain warnings.
814+
811815 As an example for `:prune_metadata`, `ExUnit` stores the AST of every
812816 assertion, so when an assertion fails we can show code snippets to users.
813817 Without this option, each time the test module is compiled, we would get a
@@ -908,7 +912,17 @@ defmodule Macro do
908912 def escape ( expr , opts \\ [ ] ) do
909913 unquote = Keyword . get ( opts , :unquote , false )
910914 kind = if Keyword . get ( opts , :prune_metadata , false ) , do: :prune_metadata , else: :none
911- :elixir_quote . escape ( expr , kind , unquote )
915+ generated = Keyword . get ( opts , :generated , false )
916+
917+ case :elixir_quote . escape ( expr , kind , unquote ) do
918+ # mark module attrs as shallow-generated since the ast for their representation
919+ # might contain opaque terms
920+ { caller , meta , args } when generated and is_list ( meta ) ->
921+ { caller , [ generated: true ] ++ meta , args }
922+
923+ ast ->
924+ ast
925+ end
912926 end
913927
914928 # TODO: Deprecate me on Elixir v1.22
0 commit comments