asoffer / Icarus

An experimental general-purpose programming language
Apache License 2.0
9 stars 2 forks source link

Local module import breaks file reading #87

Closed perimosocordiae closed 2 years ago

perimosocordiae commented 2 years ago

I'm really stumped on this one. Reproduce by creating an empty file named empty.ic and the following content in test.ic in the same directory:

-- ::= import "core.ic"
file ::= import "file.ic"
io ::= import "io.ic"
errno ::= import "errno.ic"
// This import breaks file reading somehow.
unused ::= import "empty.ic"

file.With("test.ic") open [f: file.File] {
  idx := 0 as u64
  file.Lines(f) each [line: []char] {
    idx += 1
  }
  io.Print("num lines = ", idx, !\n)
} error [e: errno.error] {
  io.Print("Error opening file (", e as u64, ")\n")
}

When I run this as is, I get:

Error opening file (2)

(where error code 2 is ENOENT, see gh-86 for my feature request on that). But if you then comment out the line where we import empty.ic, the read completes as expected:

num lines = 16
asoffer commented 2 years ago

This actually has nothing to do with the file api. A smaller reproducer:

c ::= import "c/stdio.ic"
unused ::= import "empty.ic"
c.perror("".data)

Somehow during import we're setting errno but never clearing it.