unisonweb / unison

A friendly programming language from the future
https://unison-lang.org
Other
5.8k stars 271 forks source link

UCM term parser appears to allow malformed code #5280

Open kylegoetz opened 3 months ago

kylegoetz commented 3 months ago

Describe and demonstrate the bug Please attach a ucm transcript if possible, calling out the unexpected behavior in the text. e.g.

Input:

```unison:hide
Decode.text = todo ""

ServiceExtension.internal.AuthMechanism.decode : '{Decode} AuthMechanism
ServiceExtension.internal.AuthMechanism.decode = do
  plain = do
    _ = text "PLAIN"
    PLAIN
  cramMd5 = do
    _ = text "CRAM-MD5"
    CRAM_MD5
  digestMd5 = do
    _ = text "DIGEST-MD5"
    DIGEST_MD5
  login = do
    _ = text "LOGIN"
    LOGIN
  plain <|> (do cramMd5 <|> (do digestMd5 <|> login)

ucm tells me this typechecks, but there's a parenthesis missing from the final line of `AuthMechanism.decode`.

<img width="651" alt="Screen Shot 2024-08-15 at 10 37 04 AM" src="https://github.com/user-attachments/assets/a0d00114-cf87-4c92-869c-900b793bcc3e">
Decode.text = todo ""

ServiceExtension.internal.AuthMechanism.decode : '{Decode} AuthMechanism
ServiceExtension.internal.AuthMechanism.decode = do
  plain = do
    _ = text "PLAIN"
    PLAIN
  cramMd5 = do
    _ = text "CRAM-MD5"
    CRAM_MD5
  digestMd5 = do
    _ = text "DIGEST-MD5"
    DIGEST_MD5
  login = do
    _ = text "LOGIN"
    LOGIN
  plain <|> (do cramMd5 <|> (do digestMd5 <|> login))


Adding the final parenthesis, ucm gives me the exact same output (that it typechecks, and I can add it).

**Environment (please complete the following information):**
 - unison version: release/0.5.23 (built on 2024-06-26)
 - OS/Architecture: [e.g. "macOS 12.0.1, Apple Silicon"]

**Additional context**
[Here](https://share.unison-lang.org/@kylegoetz/smtp-client/code/@kylegoetz/bug-5280-parenthesis) is a branch that has the actual correct version of the code added with the two closing parentheses.