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

Iterator doesn't seem to be matching type aliases #7567

Closed
jgaskins opened this issue Mar 20, 2019 · 6 comments
Closed

Iterator doesn't seem to be matching type aliases #7567

jgaskins opened this issue Mar 20, 2019 · 6 comments
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic

Comments

@jgaskins
Copy link
Contributor

Trying to use an Iterator to reduce memory consumption of a large result pulled back from a database (the nodes go through a few transformations before being serialized as JSON) and getting this error:

instantiating 'Iterator::Map(Indexable::ItemIterator(Array(Neo4j::Type), Neo4j::Type), Neo4j::Type, DatabaseMetric)#next()'
in /usr/local/Cellar/crystal/0.27.2/src/iterator.cr:722: type must be Neo4j::Type, not (Array(Neo4j::Type) | Bool | Float64 | Hash(String, Neo4j::Type) | Int16 | Int32 | Int64 | Int8 | Neo4j::Failure | Neo4j::Ignored | Neo4j::LatLng | Neo4j::Node | Neo4j::Path | Neo4j::Point2D | Neo4j::Point3D | Neo4j::Relationship | Neo4j::Success | Neo4j::UnboundRelationship | String | Time | Nil)

In this case, Neo4j::Type is an alias for all of those types, including Nil.

I unfortunately don't have a reduced example for this yet. I'll see if I can find one soon.

@asterite
Copy link
Member

My advice is to avoid using recursive aliases. They are slightly broken. You can use wrapper structs to achieve more or less the same result. That will probably make it work (I don't know if you control the Neo4j library).

@asterite
Copy link
Member

@jgaskins can you try doing exp.as(Neo4j::Type) with the return value of the iterator?

Otherwise, without some reproducible code we can't help.

@asterite
Copy link
Member

Actually, it's super easy to reproduce:

alias Rec = Int32 | Array(Rec)

a = [] of Rec
a << a

p a.each.map(&.itself).to_a

@asterite
Copy link
Member

And simpler:

alias Rec = Int32 | Array(Rec)

a = uninitialized Rec

f = ->(x : Rec) {}
f.call(a.itself)

I think this can be fixed, it seems to be a problem with Proc type matching and recursive aliases.

@asterite asterite added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic labels Mar 20, 2019
@asterite
Copy link
Member

@jgaskins Sorry for all the above noise, it was a really simple bug to fix. It'll probably be available in the next release.

@jgaskins
Copy link
Contributor Author

Nice work! I was going to try to get a reduced example after work today but you beat me to it! 😂 Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:compiler:semantic
Projects
None yet
Development

No branches or pull requests

2 participants