org-ql icon indicating copy to clipboard operation
org-ql copied to clipboard

level predicate when org-ql-use-preamble is nil

Open yantar92 opened this issue 4 years ago • 5 comments

I get error "Invalid Org Ql query" resolving to "void variable <" with disabled byte-compilation in the following query:

(let ((org-ql-use-preamble)) (org-ql-select (current-buffer) '(and (todo) (level > 1))))

The buffer is simply:

** TODO Heading

yantar92 avatar Apr 05 '21 09:04 yantar92

What do you mean by "disabled byte-compilation"? As you probably know, org-ql explicitly calls byte-compile in a few places.

alphapapa avatar Apr 05 '21 12:04 alphapapa

I mean that I tried to debug "Invalid Org Ql query" by removing (byte-compile... from org-ql--query-predicate. That gave more useful error.

yantar92 avatar Apr 05 '21 12:04 yantar92

I'm not an expert on Elisp's internals, but AFAIK the byte-compiler is a separate Elisp implementation from the interpreter, and as far as I'm concerned, calling byte-compile is part of org-ql's implementation, and removing that call would likely break org-ql in various ways. I'm guessing the void-variable error was caused by your doing that, because I've seen something like that before.

What is the actual problem you encountered? (If it's related to the draft PR, please resolve the lexical binding issues/warnings there first, because it's likely related.)

alphapapa avatar Apr 05 '21 12:04 alphapapa

What is the actual problem you encountered?

Sorry, my original message appears to be not clear enough.

The problem is query producing error when it should not be. Recipe on master:

  1. Create org file containing a single heading ** TODO Heading.
  2. Run M-: (let ((org-ql-use-preamble)) (org-ql-select (current-buffer) '(and (todo) (level > 1)))) <RET>
  3. Query fails with "Invalid Org QL query"

Even simpler reproducer is

  1. Create org file containing a single heading ** TODO Heading.
  2. Run M-: (org-ql-select (current-buffer) '(or (done) (level > 1))) <RET>
  3. Query fails with "Invalid Org QL query"

Note that query like (org-ql-select (current-buffer) '(and (done) (level > 1))) works just fine.

Now, confirmed that the problem exist and reproduceable on master, I tried to debug the issue further. The error "Invalid Org QL query" is produced by org-ql's stub org-ql--byte-compile-warning and hides the actual byte-compilation error. To look further, I removed the byte-compilation and allowed the Elisp interpreter to fail (byte-compiler usually fails simply because of malformed syntax - interpreter would fail in the same place). The error produced now was more descriptive than Invalid query: "void variable >". So, the issue appears to be with calling (level > 1) where Elisp attempts to evaluate function argument > (as it does for any function argument) and fails, as > is not quoted. The problem is most likely in the normalization code of the level predicate, but I failed to understand how to fix it (pcase is hard...).

yantar92 avatar Apr 05 '21 14:04 yantar92

Thank you. I probably made a mistake in the normalizer somewhere. I'll add a test case and then fix it.

alphapapa avatar Apr 05 '21 14:04 alphapapa