Thriftpy / thriftpy

Thriftpy has been deprecated, please migrate to https://github.com/Thriftpy/thriftpy2
MIT License
1.15k stars 286 forks source link

Parsing thrift with non-named enums #102

Closed mariusvniekerk closed 9 years ago

mariusvniekerk commented 9 years ago

So i have a thrift file with this spec inside it. (from the hiveserver2 CLI service).

enum TTypeId {
  BOOLEAN_TYPE,
  TINYINT_TYPE,
  SMALLINT_TYPE,
  INT_TYPE,
  BIGINT_TYPE,
  FLOAT_TYPE,
  DOUBLE_TYPE,
  STRING_TYPE,
  TIMESTAMP_TYPE,
  BINARY_TYPE,
  ARRAY_TYPE,
  MAP_TYPE,
  STRUCT_TYPE,
  UNION_TYPE,
  USER_DEFINED_TYPE,
  DECIMAL_TYPE,
  NULL_TYPE,
  DATE_TYPE,
  VARCHAR_TYPE,
  CHAR_TYPE
}

const set<TTypeId> PRIMITIVE_TYPES = [
  TTypeId.BOOLEAN_TYPE,
  TTypeId.TINYINT_TYPE,
  TTypeId.SMALLINT_TYPE,
  TTypeId.INT_TYPE,
  TTypeId.BIGINT_TYPE,
  TTypeId.FLOAT_TYPE,
  TTypeId.DOUBLE_TYPE,
  TTypeId.STRING_TYPE,
  TTypeId.TIMESTAMP_TYPE,
  TTypeId.BINARY_TYPE,
  TTypeId.DECIMAL_TYPE,
  TTypeId.NULL_TYPE,
  TTypeId.DATE_TYPE,
  TTypeId.VARCHAR_TYPE,
  TTypeId.CHAR_TYPE
]

When trying to parse this i get a

ThriftParserError: No named enum value found named 'TTypeId.BOOLEAN_TYPE'

It seems that values do not need to be names explicitly?

hit9 commented 9 years ago

Confirmed, thanks !

Apache thrift dose not throw any errors, thriftpy designs it wrong.

hit9 commented 9 years ago

Situations for errors about enums and value references:

enum A {
    x
}

const A y = 1

=> ThriftParserError: Couldn't find a named value in enum A for value 1

enum A {}

const i32 y = A

=> ThriftParserError: No enum value or constant found named 'A'

enum A {}

const i32 y = A.x

=> ThriftParserError: Cann't find name 'A.x' at line 3