Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

duplicate named enum member in different enum type cause error #363

Open
jidibinlin opened this issue Aug 4, 2022 · 4 comments
Open

duplicate named enum member in different enum type cause error #363

jidibinlin opened this issue Aug 4, 2022 · 4 comments

Comments

@jidibinlin
Copy link

jidibinlin commented Aug 4, 2022

enum FSBossStrongholdEvent {
  ready = 0;
  start = 1;
  finish = 2;
}
(pi:define-enum fs-boss-stronghold-event
    (:name "FSBossStrongholdEvent")
  (ready :index 0)
  (start :index 1)
  (finish :index 2))

 enum SAStage {
  READY = 0; 
  SIGN_UP = 1; 
  GROUP = 2; 
  TOP32 = 3; 
  FINAL = 4; 
  FINISH = 5; 
  CANCEL = 6; 
}
(pi:define-enum sa-stage
    (:name "SAStage")
  (ready :index 0)
  (sign-up :index 1)
  (group :index 2)
  (top32 :index 3)
  (final :index 4)
  (finish :index 5)
  (cancel :index 6))

fs-boss-stronghold-event`s finish conflict with sa-stags`s finish

and got this error

The constant +FINISH+ is being redefined (from 5 to 2)
   [Condition of type SB-EXT:DEFCONSTANT-UNEQL]

@jidibinlin jidibinlin changed the title duplicate named enum member in different enum type case error duplicate named enum member in different enum type cause error Aug 4, 2022
@Slids
Copy link
Member

Slids commented Aug 4, 2022

This is WAI, if you macroexpand the define enum youll see

(defconstant +finish+ 5)

and

(defconstant +finish+ 2)

easiest fix is to
a) Give them the same value
b) but them inside a message

For b:
define message SAS {
enum SAStage {
READY = 0;
SIGN_UP = 1;
GROUP = 2;
TOP32 = 3;
FINAL = 4;
FINISH = 5;
CANCEL = 6;
}
}
so you should get
+sas.finish+

See:

(defun make-enum-constant-forms (type enum-values)

@Slids
Copy link
Member

Slids commented Aug 4, 2022

Also in the readme:
Each numeric enum value is also bound to a constant by the same name but with "+" on each side:

@jidibinlin
Copy link
Author

Also in the readme: Each numeric enum value is also bound to a constant by the same name but with "+" on each side:

I think prefix enum constants with the enum name is a batter choice.

@cgay
Copy link
Contributor

cgay commented Aug 5, 2022

I think you're right. Precluding having two enum values with the same name at top-level isn't good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants