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

Interaction between generics and dirty templates #12283

Closed
andreaferretti opened this issue Sep 27, 2019 · 1 comment · Fixed by #24028
Closed

Interaction between generics and dirty templates #12283

andreaferretti opened this issue Sep 27, 2019 · 1 comment · Fixed by #24028

Comments

@andreaferretti
Copy link
Collaborator

Easier to explain with an example

import sequtils

var b = 5

type Foo[T] = object
  h, w: int

proc bar[T](foos: seq[Foo[T]]) =
  let w = foldl(foos, a + b.w, 0)

  echo w

let foos = @[Foo[int](h: 3, w: 5), Foo[int](h: 4, w: 6)]
bar(foos)

Here I am using foldl, which injects the variables a and b. Apparently, this goes in conflict with the existing variable b. This only happens inside a generic procedure, as above.

The output is

/Users/andrea/playground/nim/example.nim(14, 4) template/generic instantiation of `bar` from here
/Users/andrea/playground/nim/example.nim(9, 28) Error: undeclared field: 'w' for type system.int [declared in /Users/andrea/.mynim/devel/lib/system.nim(26, 3)]

Currently using

Nim Compiler Version 1.0.99 [MacOSX: amd64]
Compiled at 2019-09-27
Copyright (c) 2006-2019 by Andreas Rumpf

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

metagn commented Jul 25, 2024

Works now with --experimental:genericsOpenSym

metagn added a commit to metagn/Nim that referenced this issue Aug 29, 2024
@Araq Araq closed this as completed in fc853cb Aug 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants