sigmaSd / IRust

Cross Platform Rust Repl

Home Page:https://crates.io/crates/irust

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Warn about expressions with empty output

smolck opened this issue · comments

Currently, after entering something like this into the REPL:

fn test(args: i32) -> i32 {
    println!("You entered {}.", args);
    return args * 3;
}

When trying to run it with test(3), I get an error:

In: test(3)

error[E0425]: cannot find function `test` in this scope
 --> src/main.rs:3:2
  |
3 |     test(3)
  |     ^^^^ not found in this scope

If I put a semicolon at the end of test(3), so that it becomes test(3);, I get no output from the REPL, and when I type :show, I get this:

In: test(3);
In: :show
Current Repl Code:
fn main() {
    test(3);
}

Is the ability to define functions within the REPL currently not a feature, or am I missing something? If it isn't a feature, is it wanted? If so, I would be happy to help with the implementation where I can.

Hi @smolck! You need to put a semi colon after the function definition, like fn a(4) {};

The way you wrote it actually should trigger a warning, irust: are you missing a ;
Didnt the error msg appear in your case?

In the same vein #8

I think @pzmarzly is right about the surprising behaviour,

Ah nvm about the error msg it wouldnt trigger in your case, but maybe I should add more agressive warnings (maybe each time the output is ())

If you're interested you can add some analysis here https://github.com/sigmaSd/IRust/blob/master/src/irust/format.rs#L28

@sigmaSd Thanks! Now I can really make use of IRust (a great project BTW!).

If you're interested you can add some analysis here https://github.com/sigmaSd/IRust/blob/master/src/irust/format.rs#L28

Thanks, I'll look into it for sure! Beyond adding a warning message if the user doesn't put a semicolon at the end of a function definition, what other warnings would you like added? (Also, should I close this issue?)

Thanks!

Better keep it open until atleast we add a warning about this particular case cause I bet its frequent

If you figure out other warning cases feel free to add them as well or we'll just add them as they come up

@smolck Hope its alright that I implemented this c2075b5,
I just removed the input analysis, and now IRust warns about all expressions that returns a "()" (except for empty input, in that case it just create a new line)

Also I added this patch 4f650fc to disable cargo warnings, It feels they are out of place in a repl

That’s great, thanks! As a side note, do you have any other features you’d like to see implemented (or bugs you’d like fixed)? I’m happy to help where I can.

@smolck ,thanks a lot for your offer!

There are a lot of things that could be done(both bug fixes, and features), I'll write appropriate issues, (obviously if you notice something, feel free to open an issue as well!)

Currently a feature I really want is highlighting the input,
My last try was by using syntect, pseudo-code:
https://github.com/sigmaSd/IRust/blob/master/src/irust/events.rs#L9

fn handle_character() {
    let input = highlight(self.buffer);
    self.write(input);
}

highlight function https://github.com/sigmaSd/IRust/blob/master/src/irust/highlight.rs#L7

The problem with this approach is that its slow, and it makes the input laggy, not sure if I'm using syntect the right way, or if I should look for a different design to solve this problem

No problem! And that’s interesting. The highlighting is quick with :show, so I imagine that when the highlight function is called for each char, the allocated memory for each call to highlight starts to slow things down. I've opened a new issue, #40, to focus discussion on how we implement this feature.