Bug With "Import" and declared processes

Issue #59 resolved
Darío Cutillas Carrillo created an issue

Consider the following example that works:

File: main.pxt

#!

Import "mod_video"

Declare Process main_file_process ()
    Public
        int a;
        int b;
        int c;
    End
End

Process main_file_process ()
Begin
    frame;
End

Private
    int m;
End
Begin       
    set_fps ( 24, 0 );
    m = main_file_process ();

    included_process ( m );
End

Process included_process ( main_file_process p )
Begin
    say ("do nothing");
End

Now Move the process included_process to a different file.

#!

Import "mod_video"

#include "included.pxt"

Declare Process main_file_process ()
    Public
        int a;
        int b;
        int c;
    End
End

Process main_file_process ()
Begin
    frame;
End

Private
    int m;
End
Begin       
    set_fps ( 24, 0 );
    m = main_file_process ();

    included_process ( m );
End

And in file: Included.pxt

#!

Process included_process ( main_file_process p )
Begin
    frame;
End

When you try to compile the second case you get:

#!

/home/dacucar/Proyectos/tmp/pix/main.pxt:25: error: Incorrect number of parameters. Function: INCLUDED_PROCESS MinParams: 2. ( error in token: ")" ).

Changing include_params ( m ) with include_params ( m, 0 ) will make it compile.

Comments (6)

  1. Darío Cutillas Carrillo reporter

    Strangely enough, if you move the Declare sentence over the "include" the problem does not occur. I guess "included.pxt" needs to know about the declared process, so I guess It is me who did not understand correctly how Include & Declare work.

    Nevertheless I find it weird that the problem gets solved by just adding one more argument to the call.

  2. Darío Cutillas Carrillo reporter

    I change the priority to minor, but I wonder if the compiler error makes sense, perhaps it would be nice to have some kind of message saying "process type not declared?" or something that helps to know what is going on!

  3. Joseba Echevarria García repo owner

    The compiler error is consistent. Have a look at the following code:

    import "mod_say"
    
    Process cosa(a, b)
    Begin
        say(a);
        say(b);
    End
    
    Process main()
    Begin
    cosa(1, 2);
    End;
    

    We're declaring process "cosa" with two input args: a, b. But you can also write the same code in the following fashion:

    import "mod_say"
    
    Process cosa(a b)    // No "," here
    Begin
        say(a);
        say(b);
    End
    
    Process main()
    Begin
    cosa(1, 2);
    End;
    

    It will work just as well.

    What is happening with your code is that when the compiler reaches the "included_process" declaration and since it does not -yet- know anything about main_file_process, it will assume that it is a param of type int.

    In the other case the compiler does know about it and acts as expected.

    I guess there's no solution without beaking BennuGD syntax compatibility in this regard.

    Hope it helps.

  4. Darío Cutillas Carrillo reporter

    Thank you for the explanation. I did not know that the "," could be omitted!

  5. Log in to comment