I remember being taught while I was leaning French in school that whenever you saw aller followed by an infinitive, it merely formed the near future, and never meant to go to (i.e. with with purpose of) doing something. However, I have seen examples from native French speakers, and even from the book that the college I tutor at uses to teach French, of aller followed by an infinitive where the only interpretation that made sense was the latter.
So, I was wondering if there are any particularities about this usage. For example, is it only used in set expressions, is it only used when there'd be no confusion with the near future, etc?