Compilation fails on 1.17.0-dev because of lack of “version” meta key

During the upgrade of one of my libraries to 1.17.0, I got the following error message led the compilation to failing.

== Compilation error in file lib/md/parser/engine.ex ==
** (MatchError) no match of right hand side value: false
    (elixir 1.17.0-dev) src/elixir_erl_var.erl:16: :elixir_erl_var.translate/4
    (stdlib 6.0) lists.erl:2343: :lists.mapfoldl_1/3
    (stdlib 6.0) lists.erl:2344: :lists.mapfoldl_1/3
    (stdlib 6.0) lists.erl:2343: :lists.mapfoldl_1/3
    (stdlib 6.0) lists.erl:2344: :lists.mapfoldl_1/3

The line above in src/elixir_erl_var.erl:16 belongs to one of :elixir_erl_var.translate/4 clauses here

  {version, Version} = lists:keyfind(version, 1, Meta),

I would kindly appreciate any hint of under what circumstances Meta requires this :version key. The quick dig did not shed any light and I am a bit lost.

Macro.var/2 does not generate any version in meta. The only suspicious occurrence in elixir code itself would be in protocol.ex:664 as

    x = {:x, [line: line, version: -1], __MODULE__}

But amending meta manually to include version in the only place I generate vars did not help.

Thanks!

2 Likes

It seems to have been introduced in this commit.

The variable name for which it fails is context, and Meta is [{line,1278},{column,5}], so it’s probably this quote.

Could you open up an issue (if possible with a minimal example)? Thank you!

1 Like

Let me try to fix it in my code with this generous hint about line/column, and then I absolutely will open the issue.

If you don’t mind, how did you get to the variable name and meta there? Some compiler flag?

Thanks again!

1 Like

If you don’t mind, how did you get to the variable name and meta there? Some compiler flag?

Nothing fancy, just good old print debugging :smile:

translate(Meta, Name, Kind, #elixir_erl{var_names=VarNames} = S) ->
  Version = case lists:keyfind(version, 1, Meta) of
      {version, V} -> V;
      false ->
        io:format('Name: ~p~n', [Name]),
        io:format('Meta: ~p~n', [Meta]),
        io:format('Kind: ~p~n', [Kind]),
        throw(error)
    end,

which prints

Name: context
Meta: [{line,1278},{column,5}]
Kind: elixir_quote
2 Likes

Beautiful thank you!