Bars in early- and late-type discs in COSMOS