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

Dot-like operators preview feature does not parse number literals on right hand side #19806

Open
kaushalmodi opened this issue May 20, 2022 · 2 comments

Comments

@kaushalmodi
Copy link
Contributor

There's a regression on Nim devel that's breaking a previously working example.

Example

iterator `.++`[T](a: T, b: T): T =
  ## Increment each output by 2
  var res: T = a
  while res <= b:
    yield res
    inc res
    inc res

for i in 0 .++ 8:
  echo i

Current Output

/tmp/babel-9Of7gI/nim_src_8GtwME.nim(12, 16) Error: identifier expected, but got '8'

Expected Output

0
2
4
6
8

Possible Solution

  • If I change the iterator identifier to something like `..` or `==`, the same example works.

Additional Information

This example works with Nim 1.6.6. See https://play.nim-lang.org/#ix=3Ybx.

$ nim -v
Nim Compiler Version 1.7.1 [Linux: amd64]
Compiled at 2022-05-19
Copyright (c) 2006-2022 by Andreas Rumpf

git hash: 63cca93ea9bcab3c1fea39ff3789fd3a656d2db2
active boot switches: -d:release
@metagn
Copy link
Collaborator

metagn commented May 20, 2022

Simpler example:

template `.++`(a, b): untyped = a + b

discard (1 .++ 2)

The reason this is broken in devel is because dot-like operators are enabled by default. The same error is given in 1.6 if you do -d:nimPreviewDotLikeOps. For some reason dot-like operators are designed to only allow an identifier afterward. Don't know the reason for this limitation so I don't know how far this can be relaxed.

ringabout added a commit that referenced this issue Jun 22, 2022
@metagn metagn changed the title [devel regr] Number literal does not work with a custom iterator identifiers like .++ Dot-like operators preview feature does not parse number literals on right hand side Aug 28, 2023
@metagn
Copy link
Collaborator

metagn commented Aug 28, 2023

Dot-like operators are now deprecated and no longer enabled by default, so this works now, but the issue is probably still there with dot-like operators, so we can keep this open until dot-like operators are gone. (as noted above, this seems like an arbitrary limitation and shouldn't be hard to fix)

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

3 participants