Skip to content

reading a file produces odd (corrupt?) type statements #9829

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
scabug opened this issue Jun 25, 2016 · 6 comments
Closed

reading a file produces odd (corrupt?) type statements #9829

scabug opened this issue Jun 25, 2016 · 6 comments
Labels

Comments

@scabug
Copy link

scabug commented Jun 25, 2016

3 files attached (possibly 2 - mytext_repro_empty.txt is an empty file which something doesn't seem to like). Code below, modify XXX to pick files.

val source = scala.io.Source.fromFile(raw"C:\testfiles\myText_XXXX.txt")
val f = source.toSeq

using file mytext_repro_empty.txt I get

f: Seq[Char] = Stream()

which seems right. Using mytext_repro4.txt I get

f: Seq[Char] = Stream(-, ?)

which is well formed, I suppose, but don't know what the dash and question mark indicate. Using mytext_repro5.txt I get

, ?)eq[Char] = Stream(

which is evidently broken.

@scabug
Copy link
Author

scabug commented Jun 25, 2016

Imported From: https://issues.scala-lang.org/browse/SI-9829?orig=1
Reporter: ImNotTellingYouThat (intyt)
Affected Versions: 2.11.8
Attachments:

@scabug
Copy link
Author

scabug commented Jun 25, 2016

ImNotTellingYouThat (intyt) said:
Indeed, mytext_repro_empty.txt didn't come through. Create as needed.

@scabug
Copy link
Author

scabug commented Jun 25, 2016

ImNotTellingYouThat (intyt) said:
Just realised when reporting other bug that the question mark is because it's a stream. Sorry. Am a scala newbie.

@scabug
Copy link
Author

scabug commented Jun 26, 2016

Gábor Bakos (aborg) said:
I do not think that is corrupt. One might say that carriage return character should not allow overwriting the content, but I guess that is how consoles work. The first two characters of the [^mytext_repro5.txt] file are a carriage return and a new line character. The scala streams are eager in their first element, but lazy in their second, so only the first character - carriage return - is read. That character moves the cursor to the beginning of the line (f: Seq[Char] = Stream() and from that the printing continues, overwriting the first four characters (f: S) with , ?), resulting in the output you described: , ?)eq[Char] = Stream(.

What is your expected output for such input? (In the toString() method of the Streams - as you also realized -, the first value is the eagerly consumed value, the ? represents the not yet read parts.)

@scabug
Copy link
Author

scabug commented Jun 26, 2016

@som-snytt said:
Both these issues have previously stumped the chumps (experts): whether ? is real output or unprintable char in terminal; and CR messing with the output. There's a PR for pretty printing. The default printer could do more, like turn control chars into colorized escapes. scala/scala#5222

@scabug
Copy link
Author

scabug commented Jun 26, 2016

ImNotTellingYouThat (intyt) said:
@gabor, @MarkI, thanks both. Quite predictable behavour if you know what's happening, baffling if not. Ok, I don't know whether to leave it open as a UI issue to be addressed per Marki's comments about stumping smarter people, or to close it as a nonbug, so please feel free to do either as you think best.
cheers
jan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant