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

Compilation error in template when accessing the fields of a tuple constant #24698

Open
lscrd opened this issue Feb 17, 2025 · 0 comments
Open

Comments

@lscrd
Copy link

lscrd commented Feb 17, 2025

Description

The following program doesn't compile:

type Point = tuple[x, y: int]

const Origin: Point = (0, 0)

template next(point: Point): Point =
  (point.x + 1, point.y + 1)

echo Origin.x      # OK: the field is visible.
echo next(Origin)  # Compilation error: the field is not visible.

Nim Version

Nim Compiler Version 2.2.2 [Linux: amd64]
Compiled at 2025-02-06
Copyright (c) 2006-2025 by Andreas Rumpf

git hash: 6c34f62
active boot switches: -d:release

The issue is also present in the development version.

Current Output

/tmp/z.nim(9, 10) template/generic instantiation of `next` from here
/tmp/z.nim(6, 9) Error: undeclared field: 'x'

Expected Output

Successful compilation.

Known Workarounds

If the value is provided with explicit field names, the compilation is successful.

Additional Information

The problem occurs only for constant tuples with explicit field names initialized with a tuple without explicit field names.

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

1 participant