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

.this pragma doesn't work with generics #5053

Closed
Swend5 opened this issue Nov 25, 2016 · 5 comments
Closed

.this pragma doesn't work with generics #5053

Swend5 opened this issue Nov 25, 2016 · 5 comments

Comments

@Swend5
Copy link

Swend5 commented Nov 25, 2016

type
  A[T] = object
    x: T
{.this: self.}
proc testproc[T](self: A[T]) =
  echo x
type
  A = object
    x: int
{.this: self.}
proc testproc(self: A) =
  echo x

First example results in Error: undeclared identifier: 'x', second example compiles without issue.

@Swend5
Copy link
Author

Swend5 commented Nov 29, 2016

It works if the template is instantiated, maybe it has something to do with that.

type A[T] = object
  x: T
{.this: self.}
proc testproc[T](self: A[int]) =
  echo x

@branpk
Copy link
Contributor

branpk commented Jan 10, 2017

The issue is that x is looked up before testproc is instantiated, and the existence of x can depend on T. For example:

type A[T] = object
  when T is int:
    x: T

The compiler also looks up symbols when it generates an instantiation, so removing the pre-instantiation lookup doesn't appear to break anything, and it fixes this issue. But maybe it's there for a reason.

@Araq
Copy link
Member

Araq commented Jan 11, 2017

The pre-instantiation lookup is required to implement the proper "open vs closed symbol lookup" rules.

http://nim-lang.org/docs/manual.html#generics-symbol-lookup-in-generics

It's a tough issue, maybe we need to weaken the prepass if a 'this' parameter is used.

@Swend5
Copy link
Author

Swend5 commented Jan 12, 2017

Is there some temporary workaround you can think of?

@nc-x
Copy link
Contributor

nc-x commented Dec 16, 2018

{.this.} is deprecated. Can be closed?

@Araq Araq closed this as completed Dec 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants