erlang / pmod_transform

Parse transform for parameterized modules

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

behaviour won't work on a module transformed by pmod_pt

tatsuya6502 opened this issue · comments

Related to: rabbitmq/erlando#12 (comment)

It seems a module can't have both -behaviour(..) and -compile({parse_transform, pmod_pt}) at the same time. I think the reason is behaviour tries to validate callback functions after pmot_pt is applied(?)

state_t.erl

-module(state_t, [InnerMonad]).
-compile({parse_transform, do}).
-compile({parse_transform, pmod_pt}).

-behaviour(monad).
-export(['>>='/2, return/1, fail/1]).
...

monad.erl

behaviour_info(callbacks) ->
    [{'>>=',  2},
     {return, 1},
     {fail,   1}];

state_t module doesn't compile:

src/state_t.erl:21: undefined callback function '>>='/2 (behaviour 'monad')
src/state_t.erl:21: undefined callback function fail/1 (behaviour 'monad')
src/state_t.erl:21: undefined callback function return/1 (behaviour 'monad')

If I remove -behaviour(monad), it compiles. Note that each function has an extra parameter (e.g. '>>='/3, not '>>='/2)

Erlang R16B (erts-5.10.1) [source] [64-bit] [smp:4:4] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V5.10.1  (abort with ^G)
...
3> state_t:module_info().
[{exports,[{'>>=',3},
           {return,2},
           {fail,2},
           {get,1},
           {put,2},
           {eval,3},
           {exec,3},
           {run,3},
           {modify,2},
           {modify_and_return,2},
           {lift,2},
           {new,1},
           {instance,1},
           {module_info,0},
           {module_info,1}]},

Noticed the same issue.

The problem is not with the parse transform itself, but that the behaviour callback check in the compiler doesn't understand the parameterized module, whose actual functions have an additional parameter. And since the support for parameterized modules has been dropped from the compiler, there is no way this can be added now. In short, you can't combine behaviour declarations and parameterized modules.

Understood, thanks for clarifying.