Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Empty parentheses after with are parsed as Unit #3470

Open
spcfox opened this issue Jan 20, 2025 · 3 comments
Open

Empty parentheses after with are parsed as Unit #3470

spcfox opened this issue Jan 20, 2025 · 3 comments

Comments

@spcfox
Copy link
Contributor

spcfox commented Jan 20, 2025

Steps to Reproduce

The argument after with is written in parentheses. But if you leave them empty, they themselves will be parsed as Unit.

f : ()
f with ()
  f | x = x

Expected Behavior

Parsing error

Observed Behavior

Successful compilation

@spcfox
Copy link
Contributor Author

spcfox commented Jan 20, 2025

This is because the parser for with uses bracketedExpr, which can parse Unit

Idris2/src/Idris/Parser.idr

Lines 436 to 437 in 82ea4b1

<|> do b <- bounds (continueWith indents ")")
pure (PUnit (boundToFC fname (mergeBounds s b)))

@spcfox
Copy link
Contributor Author

spcfox commented Jan 20, 2025

Other syntactic constructs with parentheses are also parsed

g : (Bool, Bool)
g with (True, False)
  g | x = x

-- Not parser error
failing "Can't solve constraint between: ?x = ?x and ?p True"
  h : (b : Bool ** b = True)
  h with (True ** Refl)
    h | x = x

k : Type
k with (b : Bool ** b = True)
  k | x = x

@buzden
Copy link
Contributor

buzden commented Jan 20, 2025

Wow, didn't know that despite using with clauses a lot. This syntax seems irregular, but, maybe, it's not bad that we may omit double parens.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants