bcc icon indicating copy to clipboard operation
bcc copied to clipboard

[SCT] accessing globals with "super" dot fails

Open GWRon opened this issue 4 years ago • 5 comments

SuperStrict
Framework BRL.StandardIO

Global test:int = 10

print (.test)
Compile Error: Expression of type 'Int' cannot be invoked.

this is based on the SCT test: tests/framework/types/global_03.bmx

GWRon avatar Oct 15 '21 22:10 GWRon

Why would this ever work?

Kerntrick avatar Oct 16 '21 00:10 Kerntrick

Prepending a dot means to access something from the global (top-level) scope. You wouldn't need it in this example, but it would allow you to access the variable even if it is hidden, e.g. by an identically named local variable. The code above should work, and it does in legacy BlitzMax, but not currently in NG.

HurryStarfish avatar Oct 16 '21 00:10 HurryStarfish

I would clearly call that a syntax error even if the parser accepts it. But for the fact you say that it works classic bmax makes it a bit ambiguous. Even after 20 years, Sibly's parser has some secrets to reveal.

Kerntrick avatar Oct 16 '21 03:10 Kerntrick

As already explained, the dot allows to access the global scope.

The lengthier test file(s) should show pretty nice what it can be used for - and that it makes kinda sense.

But yeah, surely a bit rarely used ;-)

GWRon avatar Oct 16 '21 06:10 GWRon

I would clearly call that a syntax error even if the parser accepts it.

But it isn't a syntax error, just a feature you didn't know. In C++ you can write ::test to do the same thing, in C# you can use global::test; in BlitzMax you can use .test.

HurryStarfish avatar Oct 16 '21 11:10 HurryStarfish