blitz-foundation / monkey2

zlib License
3 stars 0 forks source link

Can to access enum members by enum instances #46

Closed Pharmhaus-2 closed 5 years ago

Pharmhaus-2 commented 5 years ago

Original Author: engor

Working on image processing app I found that: https://github.com/blitz-research/monkey2/blob/f3ed955eb732b224970a7ea6bf77f00cb967c563/modules/std/graphics/pixmap.monkey2#L154

Here, Formatis a property (Format:PixelFormat) of Pixmap, and it's used in Select statement as a PixelFormat equivalent. I think it's a typo.

I tried this way on test app and it works correct, so it's almost not a bug,

but if we'll try to write similar code in c#, we'll get compile time error: DataFormat.F1' cannot be accessed with an instance reference; qualify it with a type name instead

Test app:

Namespace myapp

#Import "<std>"

Using std..

Function Main()

    Local f:=DataFormat.F2

    Select f
        Case f.F1 ' <- nonsense usage of enum member
            Print "f1"
        Case f.F2
            Print "f2"
        Case f.F3
            Print "f3"
    End
End

Enum DataFormat
    F1
    F2
    F3
End

I've prepared pull request with pixmap fix.

Pharmhaus-2 commented 5 years ago

Seems to be fixed in develop.