Euphoria Ticket #525: constant expression not recognized as is in enum type

try this:

enum type  test a='?'-'0' end type 

C:\euphoria-40\work\win32\temp>eui test.ex 
c:\euphoria-40\work\win32\temp\test.ex:1 
<0138>:: Syntax error - expected to see 'type' after 'end', not a number 
enum type test a='?'-'0' end type 
                       ^ 
this is a constant expression!

Details

Type: Feature Request Severity: Normal Category: Front End
Assigned To: unknown Status: Fixed Reported Release: 4.0.0.RC2
Fixed in SVN #: View VCS: none Milestone: 5.0.0

1. Comment by jimcbrown Dec 10, 2010

This is not a bug. Both enum and type are being misused, although the error message could be improved.

2. Comment by mattlewis Dec 10, 2010

The euphoria front end does not do constant folding like this currently.

3. Comment by jeremy Dec 10, 2010

How should it be used?

4. Comment by jimcbrown Dec 10, 2010

Type is this

type test(object a) 
	return integer(a) and (a >='?' and a <= '0') 
end type 

And enum is this

enum test 
	first_test = '?', 
	second_test, 
	third_test, 
	... 
	last_test_is_zero 

5. Comment by DerekParnell Dec 10, 2010

It should be used like this ...

enum type test  
    a = 15 -- '?'-'0' 

6. Comment by DerekParnell Dec 10, 2010

Jim, Euphoria supports enum types. This means that you can easily turn an enum set into a type.

enum type colors 
  blue, black, red, orange, white 
 
function xyz( colors C) 
  ... whatever ... 
end function 
 
xyz(blue) -- ok 
xyz(100) -- fails with a type error. 

7. Comment by mattlewis Dec 10, 2010

Close, Derek, but you missed the end type:

enum type test   
    a = 15 -- '?'-'0'  
end type 

The problem raised here is not the use of enum type but the expectation of folding '?'-'0' into 15.

8. Comment by jimcbrown Dec 10, 2010

Whoops, my mistake. Looks like this is valid after all.

9. Comment by coconut Dec 10, 2010

This should be a bug because expression like '?'-'0' can be evaluate at parse as constant...

Please consider adding this to feature development.

10. Comment by coconut Dec 10, 2010

previous message should

adding this feature in future development

11. Comment by jeremy Dec 10, 2010

Converted to a feature request...

Constant Folding for enum assignments.

12. Comment by SDPringle May 22, 2015

See: hg:euphoria/rev/4825c64e9606

changeset: 6329:4825c64e9606 branch: 4.0 parent: 6327:ab5bb430c02b user: Shawn Pringle <shawn.pringle@gmail.com> date: Sat Jan 03 16:41:46 2015 -0300 files: source/parser.e tests/t_c_enum_strings.d/control.err tests/t_c_enum_strings_sneaky.d/control.err tests/t_c_enum_strings_sneaky.e tests/t_c_fwd_enum_type.d/control.err description:

  • ticket 525: enabled enum type values to be assigned any expression.

13. Comment by SDPringle Sep 24, 2015

See: hg:euphoria/rev/b2b465335529

changeset: 6365:b2b465335529 branch: 4.0 user: Shawn David Pringle B.Sc. <shawn.pringle@gmail.com> date: Wed Sep 16 00:25:09 2015 -0300 files: tests/t_enum_expressions.e description: ticket 525: unit tests added for arbitrary enum expressions

Search



Quick Links

User menu

Not signed in.

Misc Menu