qitab / cl-protobufs

Common Lisp protocol buffer implementation.
MIT License
78 stars 17 forks source link

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

Open jidibinlin opened 2 years ago

jidibinlin commented 2 years ago
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]
Slids commented 2 years ago

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: https://github.com/qitab/cl-protobufs/blob/628d71386212311fe53182a11131deaa7f767500/define-proto.lisp#L281

Slids commented 2 years ago

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

jidibinlin commented 2 years ago

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 commented 2 years ago

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