- var mapcla = v.get_mclass(self, "Map")
- if mapcla == null then return
- if v.is_subtype(mtype, colcla.get_mtype([objcla.mclass_type.as_nullable])) then
- var coltype = mtype.supertype_to(v.mmodule, v.anchor, colcla)
- assert coltype isa MGenericType
- self.coltype = coltype
+
+ # check iterator method
+ var unsafe_type = v.anchor_to(mtype)
+ if v.try_get_mproperty_by_name2(self, unsafe_type, "iterator") == null then
+ if v.try_get_mproperty_by_name2(self, unsafe_type, "iterate") == null then
+ v.error(self, "Type Error: Expected method 'iterator' in type {mtype}")
+ else
+ v.modelbuilder.error(self, "NOT YET IMPLEMENTED: Do 'for' on {mtype}")
+ end
+ return
+ end
+
+ var itdef = v.get_method(self, mtype, "iterator", true)
+ if itdef == null then
+ v.error(self, "Type Error: Expected method 'iterator' in type {mtype}")
+ return
+ end
+ self.method_iterator = itdef.mproperty
+
+ # check that iterator return something
+ var ittype = itdef.msignature.return_mtype
+ if ittype == null then
+ v.error(self, "Type Error: Expected method 'iterator' to return an Iterator or MapIterator type")
+ return
+ end
+
+ # get iterator type
+ var colit_cla = v.try_get_mclass(self, "Iterator")
+ var mapit_cla = v.try_get_mclass(self, "MapIterator")
+ var is_col = false
+ var is_map = false
+
+ if colit_cla != null and v.is_subtype(ittype, colit_cla.get_mtype([objcla.mclass_type.as_nullable])) then
+ # Iterator
+ var coltype = ittype.supertype_to(v.mmodule, v.anchor, colit_cla)