Modify

Opened 10 years ago

Closed 10 years ago

#2553 closed Bug (No Bug)

Enum unwillingly&erroneously declares/treats variables as Const

Reported by: rarirurerory Owned by:
Milestone: Component: AutoIt
Version: 3.3.9.23 Severity: None
Keywords: Cc:

Description

;Should you want to make vars unchangable constants, you simply add Const before them.
;However you _obviously_ wouldn't expect&want vars declared without Const to be treated as if they were declared WITH Const!

;but one may totally need to adjust the once Enum'erated variables, e.g. after changing an array those vars are to be used with, and s/he just can't! why, maybe Const was used? ha, nope! still cannot alter 'em!..

;please disregard those few who think this BUG is a butterfly, and fix it for (not only)your Pleasure and Glory. Thank you.

;example code:

Global Const $a=3, $b=2, $c=1
Global Const Enum $e_animal, $e_reptile, $e_fruit
Const Enum $itemColorShmalor, $itemTextBext, $itemYadayada

;-- now sans the Const --;
;-- these expected to always be changable --:
Global $x=555, $y='nope', $z=777
Enum $hehe, $haha, $hoho ;why oh why do you make these sneering v{w}ars Constant?!
                         ;noooo, stop it!..
$jk=1
$oops=1

Test()
Exit

Func test()
  do
    switch Random(1,6,1)
      case 1
        ConsoleWrite('***1***'&@LF)
        $x=777   ;this will not cause a problem
       ;$a=777   ;while this expectedly will, because $a
                 ;was declared as Const
      case 2
        ConsoleWrite('***2***'&@LF)
       ;Global $c=5 ;alright, since $c is Const, we cannot redeclare it.
        Global $y=5 ;this's fine tho, not const
      case 3
        ConsoleWrite('***3*** - expect a right error'&@LF)
        Enum $a, $b, $c ;this will Rightfully cause an error, as
                        ;these three vars are created with Const.
      case 4
        ConsoleWrite('***4')
        ;$jk=2 ; -- here would be error if $jk were Const
        ConsoleWrite('*** - THE big pesky error!'&@LF)
        Enum $jk, $oops ;and yet, while neither vars here
                        ;was made with Const, this happens:
                        ;Cannot assign values to constants.:
                        ;Enum $jk, $oops
                        ;Enum ^ ERROR
      case 5
        ConsoleWrite('***5*** - here goes the error!'&@LF)
	$hehe=';)' ;this Somehow happens to be a Const and
                   ;it breaks the script! wait, did i maybe
                   ;declared it like that? ...hmm, nope. hmm!
        Enum $haha, $hoho ;( same here
      case 6
        ConsoleWrite('***6*** - error error error!!'&@LF)
        ;$z=1 ;$z and others may or may not be --
        ;$y=2 ; -- redeclared, next line --
        Enum $z,$y,$x ;-- yup, will be faulty anyway.
    EndSwitch
  until 0
EndFunc

Attachments (0)

Change History (2)

comment:1 Changed 10 years ago by Melba23

The Help file makes it quite clear that Enum produces constants:

Enum

Enumerates constants.

constantlist | A list constants to be enumerated. 

In most languages Enum declares constants and I see no reason why AutoIt should be different, particularly as this behaviour is well-documented and long established. If you want to alter the value of items in the script, they need to declared as variables and so Enum is not a suitable function to use.

M23

comment:2 Changed 10 years ago by Melba23

  • Resolution set to No Bug
  • Status changed from new to closed

Guidelines for posting comments:

  • You cannot re-open a ticket but you may still leave a comment if you have additional information to add.
  • In-depth discussions should take place on the forum.

For more information see the full version of the ticket guidelines here.

Add Comment

Modify Ticket

Action
as closed The ticket will remain with no owner.
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.