This is more of an extended comment, but it appears that you're being forced to speculate because of a compiler failing. I've compiled the code with gfortran 4.8.3 without error, and with the expected result. Also, it seems to me that what you want to happen should happen.
The other consequence is that it appears that two separate derived types cannot have bound subroutines of the same name (as shown by the error message).
While both subroutines are called compute
they are in separate modules and this is allowed, although your use
statements make a call compute(...)
(which you aren't doing) ambiguous. If the type definitions were in the same module then you would have to resort to the procedure :: compute => compute_typex
trick, but call mytype1%compute
would still be acceptable.
I would recommend that if you're exposing the compute
subroutines through the type-binding then you have them as private
in the module, or at the very least, don't explicitly use
them. [That is, have use mod1, only : type1
.]
As for whether you're stuck with type%...
in the subroutines, then yes, I think you are. That said, under Fortran 2008 there is the associate
construct
subroutine compute(this)
class(type1), intent(inout) :: this
associate (x => this%x, y => this%y)
...
end associate
end subroutine
but that doesn't gain much in this case. And there are other terrible tricks which I won't detail.