There is a little confusion here as to what is interchangeable and what isn't, here's what the real answer is... Regardless of a .40 mag fitting in a 9mm and vice versa they are not interchangeable... Glock considers all mags interchangeable that are the same caliber ex: the G17 mag will fit in a G19 and G26... That is what Glock means regarding interchangeability...
Now it may appear that your .40 mag works, FOR NOW! The .40 mag has a different size follower than the 9mm mags do which can and most likely will prove to cause problems later on with FTF issues when you may be in a situation that you need the weapon to work most... I and others here suggest that you use the appropriate caliber mags to avoid any issues and future frustration... May cost a bit but trust me it's worth it and since you have a .40 mag you are on your way to maybe eventually purchase a G22 to compliment the 9mm, I hope that this helps you and others out
Now it may appear that your .40 mag works, FOR NOW! The .40 mag has a different size follower than the 9mm mags do which can and most likely will prove to cause problems later on with FTF issues when you may be in a situation that you need the weapon to work most... I and others here suggest that you use the appropriate caliber mags to avoid any issues and future frustration... May cost a bit but trust me it's worth it and since you have a .40 mag you are on your way to maybe eventually purchase a G22 to compliment the 9mm, I hope that this helps you and others out