brownplt / pyret-lang

The Pyret language.
Other
1.07k stars 110 forks source link

internal error in reporting? #1493

Closed shriram closed 4 years ago

shriram commented 5 years ago
data Element: elt(v, ref parent :: Option<Element>) end

fun fynd(e :: Element) -> Element:
  cases (Option) e!parent:
    | none => e
    | some(v) => fynd(e!parent.value)
  end
end

fun union(e1 :: Element, e2 :: Element):
  e1p = fynd(e1)
  e2p = fynd(e2)
  when not(e1p <=> e2p):
    e1p!{parent: e2p}
  end
end

elts = map({(v): elt(v, none)}, range(0, 10))

union(elts.get(0), elts.get(2))

This program has a bug: the line

    e1p!{parent: e2p}

ought to be

    e1p!{parent: some(e2p)}

But the error is reported weirdly:

image

This has elements of the right stuff ("expected to get Option") but the rest of it looks like an internal error, especially the "Failed while initializing a graph", which I'm not sure is an error users should ever see (?).

jpolitz commented 5 years ago

Yeah, that's a bad error report, and users shouldn't see that graph message, that's internal state leaking. This should be a fancy rendering, and just say “Failed while updating a ref field at ... because: ...”.

Working on it; I think the right thing to do here is just change how the ref-initerror renders.

jpolitz commented 5 years ago

Fixed by https://github.com/brownplt/pyret-lang/commit/73b1fe6d5e5b1ac3f0db597b4bdcd10d873a694b

I got confused by the initial error, though, because I thought the stateful warning outline was highlighting the value that violated the Option check, rather than the whole value:

image

jpolitz commented 5 years ago

(That outlining is on horizon but not master)

jpolitz commented 4 years ago
image