[stcheck] an etype constant should be the first arg to CAST

authorJulien Cristau <julien.cristau@logilab.fr>
changesetc6f45be30c6c
branchdefault
phasedraft
hiddenno
parent revision#e3a69da9c6d0 Added tag rql-version-0.33.0, rql-debian-version-0.33.0-1, rql-centos-version-0.33.0-1 for changeset 659a6b26eedc
child revision<not specified>
files modified by this revision
stcheck.py
test/unittest_stcheck.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1404918417 -7200
# Wed Jul 09 17:06:57 2014 +0200
# Node ID c6f45be30c6c14a55db96d2f355522264c90ad10
# Parent e3a69da9c6d035d6a58b5ae34178e20d0071386c
[stcheck] an etype constant should be the first arg to CAST

diff --git a/stcheck.py b/stcheck.py
@@ -460,11 +460,11 @@
1          if constant.type != 'etype':
2              return
3          if constant.value not in self.schema:
4              state.error('unknown entity type %s' % constant.value)
5          if (isinstance(constant.parent, Function) and
6 -            constant.parent.name == 'CAST'):
7 +            constant.parent.name == 'CAST' and constant is constant.parent.children[0]):
8              return
9          rel = constant.relation()
10          if rel is not None and rel.r_type in ('is', 'is_instance_of'):
11              return
12          state.error('Entity types can only be used inside a CAST() '
diff --git a/test/unittest_stcheck.py b/test/unittest_stcheck.py
@@ -64,10 +64,12 @@
13      'DISTINCT Any PF ORDERBY PN WHERE P firstname PF, P name PN',
14      # cant sort on XN, there may be different PF values for the same PF value
15      'DISTINCT Any PF ORDERBY X WHERE P work_for X, P firstname PF',
16      'DISTINCT Any PF ORDERBY XN WHERE P work_for X, P firstname PF, X name XN',
17 
18 +    'Any CAST(X, String) WHERE X eid 0',
19 +
20      )
21 
22  OK_QUERIES = (
23      '(Any N,COUNT(X) GROUPBY N WHERE X name N)'
24      ' UNION '