SpacemanDMM icon indicating copy to clipboard operation
SpacemanDMM copied to clipboard

ast's VALID_FILTER_FLAGS doesn't support non-constants

Open ZeWaka opened this issue 3 years ago • 2 comments

see:

filter(type="color", space=pick(FILTER_COLOR_HSV, FILTER_COLOR_RGB), color="#fff")
filter(type="layer", render_source = foo.render_target, flags=pick(FILTER_OVERLAY, FILTER_UNDERLAY))

error for first one:

filter(type="color") called with invalid 'space' value 'Pick([(None, Base { unary: [], term: Spanned { location: Location { file: FileId(135), line: 270, column: 57 }, elem: Ident("FILTER_COLOR_HSV") }, follow: [] }), (None, Base { unary: [], term: Spanned { location: Location { file: FileId(135), line: 270, column: 75 }, elem: Ident("FILTER_COLOR_RGB") }, follow: [] })])'

ZeWaka avatar Feb 02 '21 02:02 ZeWaka

@spookydonut

ZeWaka avatar Feb 02 '21 05:02 ZeWaka

The only sensible thing to do here is to emit no diagnostic (or maybe just an Info?) if the expression is anything other than a series of idents or numbers OR'd together.

The things we DO want to forbid are:

  1. filter(type="color", space=FILTER_COLOR_RGB|FILTER_COLOR_HSV) - using | for a non-bitflags parameter
  2. filter(type="color", space=0) - using 0 for a non-bitflags parameter
  3. filter(type="outline", flags=1) - using a magic number instead of a named constant
  4. filter(type="outline", flags=WAVE_SIDEWAYS) - using a flag that belongs to a different filter

SpaceManiac avatar May 18 '21 07:05 SpaceManiac