From 43fb85e308568743cb3b3dae815940b266addb00 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Przemys=C5=82aw=20Wojtasik?= Date: Mon, 14 Feb 2022 13:59:44 +0100 Subject: [PATCH] Fix handling generated clauses without a line --- lib/gradient/ast_specifier.ex | 1 + test/gradient/ast_specifier_test.exs | 13 +++++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/gradient/ast_specifier.ex b/lib/gradient/ast_specifier.ex index 8aa4a4f3..9d79f4b9 100644 --- a/lib/gradient/ast_specifier.ex +++ b/lib/gradient/ast_specifier.ex @@ -145,6 +145,7 @@ defmodule Gradient.AstSpecifier do def mapper({:function, anno, name, arity, clauses}, tokens, opts) do # anno has line + opts = Keyword.put(opts, :line, :erl_anno.line(anno)) {clauses, tokens} = context_mapper_fold(clauses, tokens, opts) {:function, anno, name, arity, clauses} diff --git a/test/gradient/ast_specifier_test.exs b/test/gradient/ast_specifier_test.exs index 633daa7e..ef940143 100644 --- a/test/gradient/ast_specifier_test.exs +++ b/test/gradient/ast_specifier_test.exs @@ -1362,6 +1362,19 @@ defmodule Gradient.AstSpecifierTest do ]}} = missing_type end + test "clauses without a line" do + forms = [ + {:function, 8, :__impl__, 1, + [ + {:clause, [generated: true, location: 0], + [{:atom, [generated: true, location: 0], :for}], [], + [{:atom, [generated: true, location: 0], TypedSchemaTest}]} + ]} + ] + + assert [_] = AstSpecifier.run_mappers(forms, []) + end + # Helpers def filter_specs(ast) do