brownplt / pyret-lang

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

unbound identifier has history and weird output #1664

Open shriram opened 2 years ago

shriram commented 2 years ago

Consider this program:

include tables

type Key = String

cities =
  table: code :: Key, name :: Key
    row: "PVD", "Providence"
    row: "EWR", "Newark"
    row: "SFO", "San Francisco"
  end

flights =
  table: origin :: Key, destination :: Key
    row: "EWR", "SFO"
    row: "SFO", "EWR"
    row: "PVD", "EWR"
    row: "EWR", "PVD"
  end

fun neighbors(k :: Key) -> List<Key>:
  matches = sieve flights using origin: origin == k end
  #  matches.get-column("destination")
  extract destination from matches end
end

check:
  neighbors("PVD") is [list: "EWR"]
  neighbors("SFO") is [list: "EWR"]
  neighbors("EWR").to-set() is [list: "PVD", "SFO"]
end

I run this in CPO without the type-checker on.

The third test has an error. If I then type list-to-set in the REPL, I get

image

The reference to Key is really weird. If instead I put the same name in the definitions and click Run, I get a conventional unbound identifier error.

shriram commented 2 years ago

Something stranger is going on. After that failing test, I get this output for ALL expressions in the REPL?!?

shriram commented 2 years ago

See #1665

jpolitz commented 2 years ago

Something worse – contexts are making types that are just aliases (not constructed types) behave strangely at the REPL (in CPO).

There are some small reproductions, like just declaring type Num = Number and then trying to use the REPL. Thankfully since it's so bad it'll probably be straightforward to fix.

blerner commented 2 years ago

Don't we have tests for that? (And if we do, why aren't they failing...?)