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

Regression: 0.18 code with mapIt() fails to compile on 0.19 #9093

Closed
niv opened this issue Sep 27, 2018 · 4 comments

Comments

Projects
None yet
5 participants
@niv
Copy link
Contributor

commented Sep 27, 2018

import strutils, sequtils

let inp = "a:b,c:d"

echo inp.split(",").mapIt(it.split(":"))

This used to work on 0.18 (output: @[@["a", "b"], @["c", "d"]])

0.19 fails with:

test.nim(5, 20) template/generic instantiation from here
../.choosenim/toolchains/nim-0.19.0/lib/pure/collections/sequtils.nim(690, 19) Error: type mismatch: got <seq[string]> but expected 'string = Alias'
@kaushalmodi

This comment has been minimized.

Copy link
Contributor

commented Sep 27, 2018

Calling all the recent authors of mapIt:

@LemonBoy

This comment has been minimized.

Copy link
Contributor

commented Sep 28, 2018

Not much of a regression here, for some reason iterators are preferred to procedures in type() expressions (#8901 comes to mind) and that's enough to confuse our simple-minded mapIt.

In the following snippet:

  type outType = type((
    block:
      var it{.inject.}: type(items(s));
      op))

Where op is it.split(":") the compiler picks the split iterator that returns string instead of the split procedure that returns seq[string].

@skilchen

This comment has been minimized.

Copy link
Contributor

commented Sep 28, 2018

I only fixed a typo in in this procedure. Personally I would never use it.
You could try:

echo inp.split(",").mapIt(seq[string], it.split(":"))

to get the previous result, or

echo inp.split(",").mapIt(string, it.split(":"))

to get some kind of flatmap...

@kaushalmodi

This comment has been minimized.

Copy link
Contributor

commented Sep 28, 2018

@skilchen what is the mapIt(type, arg) syntax?

Update: Answering to myself: https://nim-lang.org/docs/sequtils.html#mapIt.t,untyped,untyped,untyped. Though, this has been deprecated for a while now.


About "flatmap", that's just a string representation of the sea, right? (Would be a pain to parse that I think).

This worked when I tried:

echo inp.split(",").mapIt($it.split(":"))

But the output of that won't be very useful.

@Araq Araq closed this in 963292f Oct 24, 2018

narimiran added a commit to narimiran/Nim that referenced this issue Oct 31, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.