nim-lang / RFCs

A repository for your Nim proposals.
135 stars 26 forks source link

infix expressions should require indentation for rhs #297

Open timotheecour opened 3 years ago

timotheecour commented 3 years ago

while working on https://github.com/timotheecour/Nim/pull/418 I noticed that this is currently legal:

when true:
  let a = 1 +
  2

proposal

make it illegal (indentation error).

This stays legal:

when true:
  let a2 = 1 +
    2 +
    3 +
    4

when true:
  let a3 =
    1 +
    2 +
    3 +
    4

when true:
  let a4 = (1 +
  2)

rationale

error prone, since, in more complex cases, it wouldn't be clear that the RHS belongs to an infix expression, eg:

when true:
  template `@@`(a, b): untyped = discard
  lhs @@
  #[
  coment allowed here
  ]#
  bar()

note

https://github.com/nim-lang/Nim/issues/8258 is related but different related but different issue: https://github.com/nim-lang/Nim/pull/17352

Araq commented 3 years ago

This is arguably a parser bug. Will be interesting to see what it breaks... :-/

timotheecour commented 3 years ago

what about these, they're accepted but IMO parser should complain:

nim --eval:'echo 10.. 12'
10 .. 12
nim --eval:'echo 10- 12'
-2

(if needed with warning for a deprecation period)

Araq commented 3 years ago

These should produce warnings but are valid, afaict.