Page 1 of 1

unexpected module scope logic

Posted: Sun Mar 06, 2016 11:26 pm
by Regenduft
Hi there,

is the following code really meant to be working? It's logic seems consistent to me, but I really expected some complaint from the compiler! :shock:
(could be a nice "workaround-'til-bugfix" trick)

Code: Select all

DeclareModule redirect
  
  Macro Str( Value )
    Hex( Value )
  EndMacro
  
EndDeclareModule

Module redirect
EndModule

DeclareModule NO_redirect
EndDeclareModule

Module NO_redirect
EndModule


; as I expected...
Debug Str(123) ; output: "123"


; also as I expected...
Debug redirect::Str(123) ; output: "7B"


Debug "---------------------"


UseModule redirect


; as I expected...
Debug Str(123) ; output: "7B"


; NOT as I expected... Ö.Ö
Debug NO_redirect::Str(123) ; output: "123"

Re: unexpected module scope logic

Posted: Mon Mar 07, 2016 12:44 am
by sys64802
With PB modules everything it's open to interpretation. :lol:

You may perhaps see what's happening here this way:

Debug NO_redirect::Str(123)

Str() is not defined inside NO_redirect, but inside modules you can use PB functions so you may see it as equivalent to calling Str() from inside the empty module.

Another example:

Debug NO_redirect::Cos(3.141592)

It works, for the same reason.

I don't find it very clean, specifying the module qualifier to resolve something which it's not defined in the module maybe shouldn't work, but who knows what it's right or not ? Many things about PB modules I don't find right or opportune, I find them a promising feature but flawed.

This is even more strange:

Debug NO_redirect::Cos(#PI)

The above does not work, but if Cos() is resolved, #PI which is a PB predefined constant implicitly visible both inside and outside modules should be resolved too, so it should work.

Even this does not work:

Debug NO_redirect::Cos(NO_redirect::#PI)

To me it's just another oddity.

Re: unexpected module scope logic

Posted: Mon Mar 07, 2016 1:23 am
by Little John
Regenduft wrote:

Code: Select all

; NOT as I expected... Ö.Ö
Debug NO_redirect::Str(123) ; output: "123"
I agree with you. This is irritating and doesn't make sense.
Since Str() is not defined inside module NO_redirect, this should raise a compiler error IMHO.

Re: unexpected module scope logic

Posted: Mon Mar 07, 2016 2:05 am
by Regenduft
sys64802 wrote:Debug NO_redirect::Cos(#PI)

The above does not work [...]

Even this does not work:

Debug NO_redirect::Cos(NO_redirect::#PI)
Well... this finally breaks the (odd) logic again... :lol:


EDIT: Removed mistakable joking.


By the way, introducing a "mindwind" module doesn't work either (mind the "UseModule").

Code: Select all

DeclareModule mindwind
  
  Macro Str( Value )
    Hex( Value )
  EndMacro
  
EndDeclareModule

Module mindwind
EndModule

DeclareModule redirect
  
  UseModule mindwind
  
EndDeclareModule

Module redirect
  
  UseModule mindwind
  
EndModule

DeclareModule NO_redirect
EndDeclareModule

Module NO_redirect
EndModule


Debug Str(123) ; output: "123"
Debug redirect::Str(123) ; output: "123"

Debug "---------------------"

UseModule redirect
Debug Str(123) ; output: "123"
Debug NO_redirect::Str(123) ; output: "123"

Re: unexpected module scope logic

Posted: Wed Sep 16, 2020 3:14 pm
by Little John
Unfortunately, we all forgot to mention with which version of the compiler we encountered the issues (the version with which I previously tested the code was PB 5.42).

At least in PB 5.72, the problem seems to be fixed:

Code: Select all

Debug NO_redirect::Str(123)
Module item 'Str()' not found.

Code: Select all

Debug NO_redirect::Cos(3.141592)
Module item 'Cos()' not found.