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

can't pass @[] to template (even typed) => internal error or sigmatch error #18667

Open
timotheecour opened this issue Aug 9, 2021 · 2 comments · May be fixed by #23176
Open

can't pass @[] to template (even typed) => internal error or sigmatch error #18667

timotheecour opened this issue Aug 9, 2021 · 2 comments · May be fixed by #23176

Comments

@timotheecour
Copy link
Member

Example

when defined case1:
  template fn(b: seq[string]) =
    let d = $(b, )
  fn(@[])

when defined case2:
  template fn(b: seq[string]) =
    let d = $b
  fn(@[])

Current Output

-d:case1:
Error: internal error: getTypeDescAux(tyEmpty)

-d:case2:
Error: type mismatch: got <seq[empty], string, string, string>

Expected Output

works

Additional Information

1.5.1 6b3c77e
works with proc instead of template

mildly related: https://github.com/nim-lang/Nim/issues?q=is%3Aissue+is%3Aopen+%22tyEmpty%22

@juancarlospaco
Copy link
Collaborator

The question is if theres a literal empty seq thats not seq[empty] ?,
because @[] can match for seq[int] or any other type. The error message needs to be improved.

@solo989
Copy link
Contributor

solo989 commented Aug 10, 2021

It's literally turning

let d = $(b, )

into

let d = $(@[],)

You would have to special case for all sorts of stuff inside templates to get this and other similar situations to work.

It's also why

template hi(a : int8) =
  let
    x = a
  echo type(x) #int
hi(5)

x is an int instead of an int8.

The error messages when echo doesn't work should definitely be improved though.

The best solution would probably to have literals carry around their type information after they passed through a template with a
specific typed argument. I don't think @[] is currently a literal though.

Unfortunately you also can't do this

template hi(a : seq[int]) : untyped =
  var
    x : seq[seq[int]] = @[a]
hi(@[])

which would ideally work even if a is untyped.

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.

3 participants