M2 icon indicating copy to clipboard operation
M2 copied to clipboard

Allow lazily-evaluated code as argument to TEST

Open d-torrance opened this issue 1 year ago • 20 comments

This is a quick followup to #3419, which changed TEST from a method to a keyword so that we could do a better job of keeping track of the location of tests.

In that PR, I gave it a very low binding strength (the same as elapsedTime, etc.) But this means that it behaves much differently than it did than it was a method, e.g.,:

i1 : TEST "assert(1 + 1 " | "== 2)"

i2 : toString tests(0, User)

o2 = assert(1 + 1 == 2)

In M2 1.24.05, when TEST was still a method, we got an error:

i1 : TEST "assert(1 + 1 " | "==2)"
stdio:1:22:(3): error: no method for binary operator | applied to objects:
--            null (of class Nothing)
--      |     "==2)" (of class String)

This is because SPACE has higher binding strength than |.

We increase the binding strength of TEST to just below SPACE so that it behaves essentially the same as it did when it was a method. We keep it a bit below to mimic the right associativity of SPACE, i.e., we want TEST f x to parse as TEST (f x), not (TEST f) x.

d-torrance avatar Sep 20 '24 03:09 d-torrance