logica icon indicating copy to clipboard operation
logica copied to clipboard

Expected ‘undefined’ error, but Logica compiles fine

Open odanoburu opened this issue 4 years ago • 1 comments

A bit of context: I was translating TPC-H's 10th query, and forgot to put into scope the value of l_orderkey from the lineitem table. Logica thus took the l_orderkey == o_orderkey to mean an assignment, while I meant it as an equality test.

That Logica makes no syntactic distinction between the equality and assignment operators is explained in the Appendix of the Logica tutorial, but maybe this example shows why this can be confusing; if we had different operators the error would be clearer and easier to report to the user. Another option is to detect that l_orderkey goes unused, and therefore either it's a spurious assignment of which we might warn the user, or else it was meant as an equality test, but for some reason (a user mistake in this example) it can't be performed as intended.

@Engine("sqlite");

Query(c_custkey:, c_name:,
      revenue? += l_extendedprice * (1 - l_discount),
      c_acctbal:, n_name:, c_address:, c_phone:, c_comment:) distinct :-
  customer(c_custkey:, c_name:, c_acctbal:, c_address:,
           c_phone:, c_comment:, c_nationkey:),
  orders(o_orderkey:, o_custkey:, o_orderdate:),
  lineitem(l_extendedprice:, l_discount:, l_returnflag:),
  nation(n_nationkey:, n_name:),
  c_custkey == o_custkey,
  l_orderkey == o_orderkey,
  o_orderdate >= Date(cutoff_date),
  o_orderdate < Date(cutoff_date, "+3 month"),
  l_returnflag == "R",
  c_nationkey == n_nationkey,
  cutoff_date == "1993-10-01";
@OrderBy(Query, "revenue desc");
@Limit(Query, 20);

odanoburu avatar Aug 02 '21 15:08 odanoburu

I think adding an error for unused variable makes total sense. We already throw an error if a predicate is imported but not used, treating variables the same way seems consistent.

EvgSkv avatar Aug 09 '21 09:08 EvgSkv