Enums: case insensitive access returns wrong entry because of case sensitive members
"Enums" are ... kind of "case-insensitive-sensitive".
SuperStrict
Framework Brl.StandardIO
Enum EDay
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday
End Enum
Local day:EDay = EDay.FromString("Monday") 'nothing implemented
Print "sunday: " + eDay.sunday.ToString()
Print "Sunday: " + eDay.Sunday.ToString()
' (to test this you need the bcc/brl.mod enhanced to support FromString())
Print "From Sunday: " + EDay.FromString("Sunday").ToString()
Print "From sunDAY: " + EDay.FromString("sunDAY").ToString()
Both print "Sunday". The FromString is case-sensitive and only finds the "first" one. Last lookup leads to a runtime error (because it is not defined).
But ... if you extend the enum with a lowercase "sunday"...
Enum EDay
Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday, sunday, sunDAY
End Enum
It still compiles, and finds "Sunday" but also "sunday" and "sunDAY".
sunday: Sunday
Sunday: Sunday
From Sunday: Sunday
From sunDAY: sunDAY
-> fromString is case-sensitive (according to code ...) -> enums itself are case-sensitive -> enum "access" is case-insensitive (and bugged as it returns the "wrong" enum as seen above)
ATTENTION: Do not write this code in MaxIDE, as it auto-uppercases "sunday" to "Sunday" there.
In my opinion the enums should NOT be case-sensitive (as BlitzMax is not case-sensitive either). Making them case-insensitive means also having to adjust the FromString() to be case-insensitive too.
I think so too. Case sensitivity in enumerations in a case-insensitive language seems odd.
@mingwya , I know ... Russia, different time zone, ... In other words: Brucey already made things case-insensitive (despite "toString" using the written casing in the definition). You need to update brl/bcc to get them.
@GWRon I already managed to rewrite the engine for enumerations... and it stopped working =() The error occurs in the C code... it seems to be something related to enumeration arrays... I'll try to write simplified code that reproduces this error and post it here.
@GWRon @woollybah I updated BlitzMax ( BRL, PUB, Text, BCC, BMK ) . error popped up.
libuuid is Linux/mac os only. So not available for Windows.
Edit: might be that libuuid supports windows - but grp.h is not available on a Windows OS. Brucey added this grp.h-dependency in https://github.com/bmx-ng/pub.mod/commit/74d76a53e679d8a7c0c592625d85e7fb5c6c78dd
and libuuid added this 4 years ago: https://github.com/util-linux/util-linux/commit/17fc8693cd60733227204fe31395575778984e3c
In the old version of PUB, this module builds on Windows without any problems... And as far as I remember, the module worked on Windows. By the way, after updating BlitzMax, the problem with enumerations in the engine disappeared. Everything works fine now. Thanks, guys!
Enums should be working properly now.