Skip to content

Delegate conflicts with exprecs #3

Open

Description

@aberman

I tried to use exprecs with the Delegate annotation and exprecs fails when executing code. For example:

-module(test).

-compile({parse_transform, exprecs}).
-export_records([myrecord]).
-include_lib("annotations/include/annotations.hrl").
-include("records.hrl").

-delegate([{delegate, ["id", "name"]},
{args, ['$1']},
{arity, 1}]).
get(Property, #myrecord{} = Rec) when is_atom(Property) ->
'#get-'(Property, Rec).

When I try to do test:id(Rec), I get:

** exception error: undefined function test:'#exported_records-'/1

'#exported_records-'/0 exists but not /1 and when you change the args in the delegate tag it affects this value. If you pass no args, no matter what you put in the get function yields '#exported_records-'/0.

Activity

  1. hyperthunk commented on May 23, 2012

    @hyperthunk
    Owner

    Shouldn't that argument spec be more like:

    -delegate([
    {delegate, ["id", "name"]},
    {args, ['$T', '$1']},
    {arity, 1}]).
    get(Property, #myrecord{} = Rec) when is_atom(Property) ->
    '#get-'(Property, Rec).

    That way, the property (name) gets passed correctly. Although on my machine, I was unable to make this generate any delegate code at all, but then I have just rebuilt a new laptop.

    Also, I'm a little hazy on whether or not the $n arguments array is indexed from zero or one - you'll have to check the code to make sure.

    If this is still bothering you comment back and I will get a look at it some time this week.

    Cheers,
    Tim

  2. aberman commented on May 23, 2012

    @aberman
    Author

    Thanks for the reply, Tim. That doesn't fix the issue. If you pass two values in the args param you then get "** exception error: undefined function test:'#exported_records-'/2." No matter what you pass in the args gets passed to the exported_records function. I'm unclear why the delegate is not attached to the "get" function. Looking at the delegate code I notice that you don't have an -annotation('function') at the top of the file. I don't know if that's by design or not.

    Thanks again!

    Andrew

  3. aberman commented on May 23, 2012

    @aberman
    Author

    I was just now able to fix it by moving the exprecs code below the annotations include. This seems like a band-aid fix to me, but it's working now, so I'll leave it up to you if you want to look at this or not. Close at will :-) Thanks again for your hard work on this stuff!

  4. hyperthunk commented on May 23, 2012

    @hyperthunk
    Owner

    Thanks for keeping me in the loop. I do believe that based on what you've said in that last comment, that there is a clash between the two parse transforms. I will leave this issue open until I've had time to investigate properly, but either way I'm glad you've got it working! :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions