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

pass varargs[seq[T]] to iterator give empty seq #12576

Closed
slangmgh opened this issue Nov 2, 2019 · 3 comments · Fixed by #15085
Closed

pass varargs[seq[T]] to iterator give empty seq #12576

slangmgh opened this issue Nov 2, 2019 · 3 comments · Fixed by #15085
Labels

Comments

@slangmgh
Copy link
Contributor

slangmgh commented Nov 2, 2019

When pass varargs[seq[T]] to iterator, only the first arg is valid, the following is always empty.

Example

iterator ff(sq: varargs[seq[int]]): int =
   for x in sq:
      echo x

for x in ff(@[1,2], @[1,2,3]):
   echo x

Current Output

@[1,2]
@[]

Expected Output

@[1,2]
@[1,2,3]
$ nim -v
Nim Compiler Version 1.1.0 [Windows: i386]
Compiled at 2019-11-02
Copyright (c) 2006-2019 by Andreas Rumpf

active boot switches: -d:release
@slangmgh
Copy link
Contributor Author

slangmgh commented Nov 3, 2019

The program run fine with v0.20.0 and breaks with v0.20.2.

@slangmgh
Copy link
Contributor Author

slangmgh commented Nov 3, 2019

The following code in transf.nim casue the problem, maybe paFastAsgnTakeTypeFromArg type doesn't be handled correctly in proc transformFor:

proc putArgInto(arg: PNode, formal: PType): TPutArgInto =
  # This analyses how to treat the mapping "formal <-> arg" in an
  # inline context.
  if formal.kind == tyTypeDesc: return paDirectMapping
  if skipTypes(formal, abstractInst).kind in {tyOpenArray, tyVarargs}:
    case arg.kind
    of nkStmtListExpr:
      return paComplexOpenarray
    of nkBracket:
      return paFastAsgnTakeTypeFromArg    # oops
    else:
      return paDirectMapping    # XXX really correct?
                                # what if ``arg`` has side-effects?

@slangmgh
Copy link
Contributor Author

slangmgh commented Nov 3, 2019

It is caused by fixing issue #8316.

@ghost ghost added the varargs label Jul 27, 2020
Clyybber pushed a commit that referenced this issue Jul 27, 2020
* Add a test-case for #12576

* Add a test-case for #12523
mildred pushed a commit to mildred/Nim that referenced this issue Jan 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant