ponyc
ponyc copied to clipboard
generic type issue when using itertools
Description
I came across this issue when trying to create an iterator to iterate over a Map[String, Map[String, T]], where T can be Any #share. It looks like the code should compile, and it compiles with ponyc prior to 0.22.0.
Sorry I don't have more information here, I see a problem but I've only found one somewhat convoluted way to reproduce it and I'm not really sure what's going on.
Steps to Reproduce
Try to compile the following code:
use "collections"
use "itertools"
type Key is String
class KeyToStepInfo[Info: Any #share]
let _info: Map[String, Map[Key, Info]]
new create() =>
_info = _info.create()
fun pairs() =>
Iter[(String, Map[Key, Info] box!)](_info.pairs()).
map[(Iter[String], Iter[(Key, Info)])]({
(k_m) => (Iter[String].repeat_value(k_m._1),
Iter[(Key, Info)](k_m._2.pairs()))
})
actor Main
new create(env: Env) =>
None
Expected Result
The code should compile.
Actual Result
When I compile the code I get the following error message:
Building builtin -> /usr/local/lib/pony/0.23.0-59eac3b1f/packages/builtin
Building . -> /Users/aturley/development/pony-playground/oof
Building collections -> /usr/local/lib/pony/0.23.0-59eac3b1f/packages/collections
Building ponytest -> /usr/local/lib/pony/0.23.0-59eac3b1f/packages/ponytest
Building time -> /usr/local/lib/pony/0.23.0-59eac3b1f/packages/time
Building itertools -> /usr/local/lib/pony/0.23.0-59eac3b1f/packages/itertools
Error:
/Users/aturley/development/pony-playground/oof/main.pony:16:29: argument not a subtype of parameter
Iter[(Key, Info)](k_m._2.pairs()))
^
Info:
/Users/aturley/development/pony-playground/oof/main.pony:16:29: argument type is MapPairs[String val, Info #share, HashEq[String val] val, HashMap[String val, Info #share, HashEq[String val] val] box] ref
Iter[(Key, Info)](k_m._2.pairs()))
^
/usr/local/lib/pony/0.23.0-59eac3b1f/packages/itertools/iter.pony:9:14: parameter type is Iterator[(String val, Info #share)] ref
new create(iter: Iterator[A]) =>
^
/Users/aturley/development/pony-playground/oof/main.pony:6:27: Any #share is not a subtype of Info val: the type parameter has no lower bounds
class KeyToStepInfo[Info: Any #share]
^
/usr/local/lib/pony/0.23.0-59eac3b1f/packages/collections/map.pony:379:40: (HashMap[String val, Info #share, HashEq[String val] val] box->Info #share, HashMap[String val, Info #share, HashEq[String val] val] box->Info #share) is not a pairwise subtype of (Info val, Info tag)
fun pairs(): MapPairs[K, V, H, this->HashMap[K, V, H]]^ =>
^
/usr/local/lib/pony/0.23.0-59eac3b1f/packages/collections/map.pony:469:24: (String val, HashMap[String val, Info #share, HashEq[String val] val] box->Info #share) is not a pairwise subtype of (String val, Info #share)
fun ref next(): (M->K, M->V) ? =>
^
/usr/local/lib/pony/0.23.0-59eac3b1f/packages/collections/map.pony:469:3: method result (String val, HashMap[String val, Info #share, HashEq[String val] val] box->Info #share) is not a subtype of (String val, Info #share)
fun ref next(): (M->K, M->V) ? =>
^
/usr/local/lib/pony/0.23.0-59eac3b1f/packages/collections/map.pony:469:3: MapPairs[String val, Info #share, HashEq[String val] val, HashMap[String val, Info #share, HashEq[String val] val] box] ref is not a subtype of Iterator[(String val, Info #share)] ref: method 'next' has an incompatible signature
fun ref next(): (M->K, M->V) ? =>
^