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

template treated as template(): untyped when using in template without bracket #14330

Closed
slangmgh opened this issue May 13, 2020 · 5 comments
Closed

Comments

@slangmgh
Copy link
Contributor

Example

type Buffer = object
   lines: seq[string]

var buffer: Buffer

proc p1(ss: seq[string]) = discard
template code_lines: untyped = buffer.lines
template p2() = p1(code_lines)    # change `template` to `proc` make the compiler success

p2()

Current Output

D:\Tool\Nim\tmp\a12.nim(10, 3) Error: type mismatch: got <template (): untyped>
but expected one of:
proc p1(ss: seq[string])
  first type mismatch at position: 1
  required type for ss: seq[string]
  but expression 'code_lines' is of type: template (): untyped

expression: p1(code_lines)

Expected Output

compile success.

Possible Solution

change the second template to proc

Additional Information

$ nim -v
Nim Compiler Version 1.3.3 [Windows: i386]
Compiled at 2020-05-13
Copyright (c) 2006-2020 by Andreas Rumpf

active boot switches: -d:release
@kaushalmodi
Copy link
Contributor

I think that the behavior to see is expected. You are trying to expand the code_lines template, right? If so, I think that it should have the parens.

Your code modified: https://play.nim-lang.org/#ix=2lRb

@slangmgh
Copy link
Contributor Author

But the following code is ok. I think people will be confused why the proc cannot change to template.

proc p2()  = p1(code_lines)

@slangmgh
Copy link
Contributor Author

This is the same bug with #14332, add {.dirty.} to the template can fix the problem too.

@metagn
Copy link
Collaborator

metagn commented May 13, 2020

Duplicate of #13515

@timotheecour
Copy link
Member

closing as duplicate

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

4 participants