Repository navigation
Error on function literals in math - #7866
Conversation
b8e556c to
6eecef6
Compare
|
For the hint, I think it should detect whether parentheses are opened after some whitespace and suggest "to call the If no parentheses are present, I think the current hint could be rephrased to "to call the |
I took a look to understand the current approach and am happy to learn about the alternative. Let's discuss this later. |
d5d9094 to
5c638d2
Compare
5c638d2 to
57ab738
Compare
57ab738 to
eb63506
Compare
|
I have now implemented the alternative design for |
599a4bd to
68c9b56
Compare
1439a16 to
be8b45e
Compare
|
I've been working on other things for a while, but now it's time to get back to improving math syntax! For this PR, I realized that there was a nice simplification if we just return a This PR also has a new second commit that adjusts the error range when we're hinting for delimiters to use a sub-range of the overall Unfortunately, I still do not have a fix that can add hints when a function literal is next to parens but is inside an operator, like in I would love to hear if anyone has feedback on any of the new error messages or test cases! |
| ) $ | ||
|
|
||
| --- math-func-literal-basic eval --- | ||
| // Error: 3-6 this does not call the `mat` function |
There was a problem hiding this comment.
I feel like this doesn't fit the style of an error message. Plus, it's kind of redundant with the hint.
The error message should more closely stick to what exactly went wrong, so perhaps something like "cannot use function without call"?
There was a problem hiding this comment.
I agree that this feels more like a hint than an error, and with the others it's generally redundant; below, the "expected content, found function" is more useful as an error to me, but perhaps also difficult to understand for newcomers. Not entirely sure what I'd want it to be (the idea of functions having a sort of debug representation isn't the most straightforward), but perhaps something along the lines of "function type does not represent mathematical content"?
Though wording aside, this is a pretty sweet! A welcome change with really nice hints that'll probably prevent quite a few headaches 😅
There was a problem hiding this comment.
How about "cannot display function" and add the current message as a hint?
There was a problem hiding this comment.
I've updated to that
be8b45e to
789c501
Compare
cf03aea to
861d843
Compare
07f8891 to
04de0fa
Compare
04de0fa to
413da78
Compare
|
Looks good now! :) |
|
I know I'm late, but what was the rationale behind making this an error? Since functions can be displayed in markup mode as monospace names, it seems a bit asymmetric to forbid it in math mode. Was there another motivation related to the larger math parsing refactor? |
|
Yes, we've settled on the syntax refactor making |
Part of the Math Syntax Refactor
This PR is part of the exhaustive math syntax refactor. It should be considered exploratory, and not necessarily a final decision, even if merged to the
math-syntaxbranch. Non-specific feedback for this change should go in one of its related issues.This PR causes function literals placed in math to produce errors instead of rendering the function name as monospace text. Function literals in markup mode still render as before.
This depends on PR #7865. Only the last commit is new.
This is in part a preparation for resolving The Math Mode Problem (cf. #7084), but that will come later.
Here is one of the test cases showing the new error and hint. I am not fully satisfied with the wording, so feel free to give suggestions :)
This is implemented by breaking out the
Evalimpls ofMathIdentandFieldAccessinto free functions so that when called withEval::eval(), they produce an error on function literals in math, but are still able to be evaluated inMathCall::eval()without producing an error.I'm not quite happy with the amount of complication required for this approach to work with field accesses, and an alternative I considered was to encode the difference between
MathIdentandIdentinto a more genericMathIdentWrapperwhich could directly contain bothIdentandFieldAccessnodes when used in math. I didn't go with that for now because it requires a lot of code churn, but it does feel a bit conceptually cleaner. I also believe it could simpify #7407, although have not tried it.