Iterating over `HashMap keys` gives a funny error message #361

fredreichbier opened this Issue Dec 21, 2011 · 5 comments


None yet
3 participants

fredreichbier commented Dec 21, 2011

This code:

import structs/HashMap

hm := HashMap<String, String> new()
hm put("foo", "bar")

for(key in hm keys) { key println() }


sdk/structs/ArrayList.ooc:186:36 ERROR Undefined symbol 'this'
    iterator: func -> BackIterator<T> { return ArrayListIterator<T> new(this) }


Sure, it shouldn't use keys but getKeys(), but this doesn't look very cool. :D


alexnask commented Dec 22, 2011

Ooh really weird. I'll have to look into the way for ... in blocks are handled in rock. If I understand correctly, it automatically searches for an iterator() method then constructs some calls right? My guess is that it does not construct a hm keys iterator() call but something different, wich leaves this undefined? :/


fredreichbier commented Dec 22, 2011

Hmm, I don't know really. This fails with the same message:

import structs/ArrayList

Generic: class <T> {
    value: ArrayList<T>

Generic<Int> new() value iterator()

alexnask commented May 3, 2012

Casting value to ArrayList<Int> and then calling iterator() works. Should the code without the cast work? In ooc, we are supposed to cast types of generic types before using them right? But in this case, shouldn't the info rock has be enough to automatically decide that value is of type ArrayList<Int> ?


nddrylliog commented Feb 16, 2013

Is that still a problem in 96x btw? We've fixed lots of stuff since. /cc @shamanas


alexnask commented Feb 16, 2013

Ok so the second testcase provided now works.
The first one fails with 'ERROR No such function println() for K (you can't call methods on generic types! you have to cast them first)'.
Casting key to String leads to this error: 'ERROR Undefined symbol 'K'' while casting hm keys to ArrayList<String> works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment