Skip to content

Print diagnostics in each interactive loop - #2809

Merged
ubaidsk merged 1 commit into
lcompilers:mainfrom
hankluo6:print_error
Sep 12, 2024
Merged

ubaidsk merged 1 commit into
lcompilers:mainfrom
hankluo6:print_error

Conversation

@hankluo6

Copy link
Copy Markdown
Contributor

Fixed #2807
Fixed #2757

In interactive mode, some errors or suggestions were added to the diagnostics but did not throw any errors. These should also be printed.

@certik
certik requested a review from ubaidsk September 12, 2024 17:40
@ubaidsk

ubaidsk commented Sep 12, 2024

Copy link
Copy Markdown
Collaborator

I think this works and does the job:

(lp) ubaid@DESKTOP-TEN39M0:~/projects/lpython$ ./src/bin/lpython
Interactive LPython. Experimental prototype, not ready for end users.
LPython version: 0.22.0-53-g1ef4675ae
  * Use Ctrl-D to exit
  * Use Enter to submit
  * Use Alt-Enter or Ctrl-N to make a new line
    - Editing (Keys: Left, Right, Home, End, Backspace, Delete)
    - History (Keys: Up, Down)
>>> i: i32 = 5                                                                                                                                 1,11  ]
>>> from math import sin                                                                                                                       1,21  ]
>>> sin(i)                                                                                                                                     1,7   ]
semantic error: `x` argument of `Sin` must be real or complex
 --> input:1:5
  |
1 | sin(i)
  |     ^ 


Note: Please report unclear or confusing messages as bugs at
https://github.com/lcompilers/lpython/issues.
>>> pow(2, 3)                                                                                                                                  1,10  ]
style suggestion: Could have used '**' instead of 'pow'
 --> input:1:1
  |
1 | pow(2, 3)
  | ^^^^^^^^^ '**' could be used instead


Note: Please report unclear or confusing messages as bugs at
https://github.com/lcompilers/lpython/issues.
8
>>>     

@ubaidsk ubaidsk left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks for fixing this!

Comment thread src/bin/lpython.cpp
if (res.ok) {
r = res.result;
std::cerr << diagnostics.render(lm, compiler_options);
diagnostics.clear();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On second thought, I think this approach is good to print style info/warnings. But for printing errors (semantic errors like in #2757), we should fix the python_ast_to_asr to return the result as not ok (that is res.ok = False).

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I created a new issue for this here #2810. I think this PR is good to merge.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed this as well. The reason is that for the intrinsic functions, we used append_error instead of throwing a semantic error. This could potentially be resolved by throwing the error later from python_ast_to_asr if the intrinsic function returns null.

@ubaidsk
ubaidsk merged commit 7eb2bea into lcompilers:main Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interactive LPython delays the response or crashes i: i32=5; sin(i) should give an error message in interactive mode

2 participants