bmx-ng / bcc

A next-generation bcc parser for BlitzMax
zlib License
33 stars 12 forks source link

[SCT] accessing globals with "super" dot fails #564

Open GWRon opened 3 years ago

GWRon commented 3 years ago
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

Kerntrick commented 3 years ago

Why would this ever work?

HurryStarfish commented 3 years ago

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.

Kerntrick commented 3 years ago

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.

GWRon commented 3 years ago

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 ;-)

HurryStarfish commented 3 years ago

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.