If you take the extension function outside of the bounds of the RectangleRange (and replace maxX to make it valid code), it compiles. That would suggest that extension functions cannot be within another type. I think that makes sense, because otherwise, you would be making an extension function that is only valid when accessed as a result of the iterator being called...and if that was valid, it could lead to the extension function having different implementations depending on the call stack (which surely would be confusing).