erg-lang / erg

A statically typed language compatible with Python
http://erg-lang.org
Apache License 2.0
2.69k stars 55 forks source link

REPL does not support multi-line errors #248

Closed GreasySlug closed 7 months ago

GreasySlug commented 1 year ago

Describe the bug?

A block is created in the REPL, and if there is an error there, a blank line is displayed.

Reproducible code

>>> for! 0..5,i -> 
...    print! i

Expected result

1 | for! 0..5, i -> 
  :            -
2 |    print! i
  : -----------
  :           |- expected: (?T(: Type)) => NoneType
  :           `- but found: (i: ?3(<: Ref(Obj))) -> NoneType

Actual result

1 | 
  :           -
2 | 
  : -----------
  :           |- expected: (?T(: Type)) => NoneType
  :           `- but found: (i: ?3(<: Ref(Obj))) -> NoneType

Additional context

The REPL uses reread()

    let codes = if e.input().is_repl() {
        vec![e.input().reread()]
    } else {
        e.input().reread_lines(ln_begin, ln_end)
    };

However, this only gets the last element

    pub fn reread(&self) -> String {
        self.buf.last().cloned().unwrap_or_default()
    }

REPL exits the block if there is only a newline So the last element will be a newline only Perhaps that is what it shows

Erg version

0.5.12

Python version

No response

OS

No response

mtshiba commented 1 year ago

The constant GLOBAL_STDIN holds all standard input received. reread_lines(x, y) simply returns buf[x - 1 ..= y - 1], but since the REPL resets the number of lines each time, a new method should be implemented for that.

C-BJ commented 7 months ago

Should this be closed?

GreasySlug commented 7 months ago

@C-BJ Yes, thank you