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

untyped argument used inside generic body gives undeclared identifier due to generic symbol resolution prepass #5975

Open
martincohen opened this issue Jun 11, 2017 · 1 comment

Comments

@martincohen
Copy link

I've encountered a strange problem with template and untyped argument. I'm not sure what exactly is going on. It feels like compiler bug really, as the two examples bellow are only different on wheteher I pass batch: var BatchArg to the function. Once I do, the template's untyped argument is being checked and results in undeclared identifier.

Any hints appreciated.

type Quad* = object
    a*: int

type Batch* = object
    a*: int

type BatchArg = Batch or ref Batch

# Works
proc testB*() =
    var quad = Quad()
    template attrib(member: untyped) =
        echo quad.member
    
    attrib(a)

testB()

# Doesn't work
proc testA*(batch: var BatchArg) =
    var quad = Quad()
    template attrib(member: untyped) =
        echo quad.member
    
    attrib(a) # << Error: undeclared identifier: 'a'

var batch = Batch()
testA(batch)
@timotheecour
Copy link
Member

timotheecour commented Jun 26, 2020

reduced:

  proc fun[T]() =
    template bar(member: untyped) = discard # works if that template is declared outside fun
    bar(a) # << Error: undeclared identifier: 'a'

it's caused by generic symbol resolution prepass (aka early symbol resolution) IIUC
=> refs: #8677

we need to check whether this bug is a dup

@timotheecour timotheecour changed the title Template with untyped argument resulting in undeclared identifier Template with untyped argument resulting in undeclared identifier (generic symbol resolution prepass) Jun 26, 2020
@timotheecour timotheecour changed the title Template with untyped argument resulting in undeclared identifier (generic symbol resolution prepass) untyped argument used inside generic body gives undeclared identifier due to generic symbol resolution prepass Jun 27, 2020
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

4 participants