Uploaded image for project: 'NHibernate [Moved to GitHub]'
  1. NH-3000

QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. when projection contains complex code [regression]

    Details

    • Sprint:

      Description

      I upgraded to current trunk today, and noticed some of our tests are failing.

      The following works in NHibernate 3.2, so this is a regression bug

      In one test we have a code like this (simplified):

      var lookup = new[]

      { 1, 2, 3, 4 }

      .ToDictionary(x => x, x => new { Codes = new[]

      { x }

      });
      var query = from item in Session.Query<Foo>()
      select new

      { index = Array.IndexOf(lookup[item.Id].Codes, item.Id, 0)/7, }

      ;

      var result = query.ToList();

      The first line is irrelevant. Anyway, it seems NHiberante gets confused by the relatively complicated coed in the select clause, as it throws the following exception:

      NHibernate.Hql.Ast.ANTLR.QuerySyntaxException: Exception of type 'Antlr.Runtime.NoViableAltException' was thrown. [.Select[Namespace.Foo,<>f__AnonymousType1`1[[...etc
      at NHibernate.Hql.Ast.ANTLR.ErrorCounter.ThrowQueryException() in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Hql\Ast\ANTLR\ErrorCounter.cs: line 69
      at NHibernate.Hql.Ast.ANTLR.HqlSqlTranslator.Translate() in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs: line 570
      at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Analyze(String collectionRole) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs: line 425
      at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.DoCompile(IDictionary`2 replacements, Boolean shallow, String collectionRole) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs: line 363
      at NHibernate.Hql.Ast.ANTLR.QueryTranslatorImpl.Compile(IDictionary`2 replacements, Boolean shallow) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Hql\Ast\ANTLR\QueryTranslatorImpl.cs: line 72
      at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode ast, String queryIdentifier, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Hql\Ast\ANTLR\ASTQueryTranslatorFactory.cs: line 43
      at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Hql\Ast\ANTLR\ASTQueryTranslatorFactory.cs: line 27
      at NHibernate.Engine.Query.HQLExpressionQueryPlan.CreateTranslators(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs: line 34
      at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs: line 23
      at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs: line 17
      at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Engine\Query\QueryPlanCache.cs: line 88
      at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Impl\AbstractSessionImpl.cs: line 312
      at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Impl\AbstractSessionImpl.cs: line 268
      at NHibernate.Linq.DefaultQueryProvider.PrepareQuery(Expression expression, ref IQuery query, ref NhLinqExpression nhQuery) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Linq\DefaultQueryProvider.cs: line 69
      at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Linq\DefaultQueryProvider.cs: line 33
      at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression) in d:\BuildAgent-03\work\642d14aa2ecb6f73\src\NHibernate\Linq\DefaultQueryProvider.cs: line 40
      at Remotion.Linq.QueryableBase`1.GetEnumerator() in :line 0
      at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
      at System.Linq.Enumerable.ToList(IEnumerable`1 source)

        Attachments

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              kkozmic k
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Who's Looking?