DDC-4002: Identifiers matching a different token are not usabled for alias result variables #4886

Open
opened 2026-01-22 14:51:28 +01:00 by admin · 2 comments
Owner

Originally created by @doctrinebot on GitHub (Nov 16, 2015).

Originally assigned to: @guilhermeblanco on GitHub.

Jira issue originally created by user stof:

The following query does not work:

SELECT g AS group, SIZE(g.members) AS member_count FROM Incenteev\WebBundle\Entity\Group g WHERE g.category = :category ORDER BY g.name ASC, g.id ASC

This triggers a very confusing error:

[Semantical Error] line 0, col 17 near ', SIZE(g.members)': Error: Class ',' is not defined.

This happens because group is matched as a T*GROUP token, not as a T_IDENTIFIER. The lexer has a comment saying that all tokens which are also valid identifiers must have a value >= T*IDENTIFIER, but I don't see any place relying on this, making these token reserved for any place using them. This is annoying as it means that it is impossible to alias the result as group when using DQL.

Regarding the confusing error message, I have an idea to improve it in some cases (including the one described here) as the current implementation does not actually reflect the documented EBNF: the implementation allows to use AS without putting an AliasResultVariable after it, while the EBNF does not. If we consider that AS needs the AliasResultVariable after it, we can at least have a better error message

Originally created by @doctrinebot on GitHub (Nov 16, 2015). Originally assigned to: @guilhermeblanco on GitHub. Jira issue originally created by user stof: The following query does not work: ``` sql SELECT g AS group, SIZE(g.members) AS member_count FROM Incenteev\WebBundle\Entity\Group g WHERE g.category = :category ORDER BY g.name ASC, g.id ASC ``` This triggers a very confusing error: `[Semantical Error] line 0, col 17 near ', SIZE(g.members)': Error: Class ',' is not defined.` This happens because `group` is matched as a `T*GROUP` token, not as a `T_IDENTIFIER`. The lexer has a comment saying that all tokens which are also valid identifiers must have a value `>= T*IDENTIFIER`, but I don't see any place relying on this, making these token reserved for any place using them. This is annoying as it means that it is impossible to alias the result as `group` when using DQL. Regarding the confusing error message, I have an idea to improve it in some cases (including the one described here) as the current implementation does not actually reflect the documented EBNF: the implementation allows to use `AS` without putting an AliasResultVariable after it, while the EBNF does not. If we consider that `AS` needs the AliasResultVariable after it, we can at least have a better error message
admin added the Bug label 2026-01-22 14:51:28 +01:00
Author
Owner

@patrick-mcdougle commented on GitHub (Mar 16, 2016):

I had the same issue when naming a result field "count". Mine was at the end of the select statement which made it even more confusing when it said [Semantical Error] ... near FROM...

@patrick-mcdougle commented on GitHub (Mar 16, 2016): I had the same issue when naming a result field "count". Mine was at the end of the select statement which made it even more confusing when it said `[Semantical Error] ... near FROM...`
Author
Owner

@benbor commented on GitHub (Mar 10, 2017):

@patrick-mcdougle i had the same issue for v2.5.6. But for master branch it's works fine.

@benbor commented on GitHub (Mar 10, 2017): @patrick-mcdougle i had the same issue for v2.5.6. But for `master` branch it's works fine.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#4886