I'm looking at this, since it may relate to confusion with import/export, but @findleyr , you may also want to take a look when you get a chance, since the error happens in types2. Seems like we may somehow confused distinct type parameters during export/import across multiple packages. Problem goes away if the type params in definition of Ap2 are renamed (e.g. to A2/B2).
The bug relates to the type parameter B being specified in Ap1, but not actually being used in Ap1 (applies to Ap2 as well). Because B is not used, we are somehow referencing the wrong B during definition and then export. Doesn't always cause a visible problem, but sometimes does (as in this issue).