HiCustomer and welcome to JA!
I'm sure there are many different computer programs running on various brands of cash register, but the way I've seen it work is this (and this also makes the most sense for the programmer to do):
If an employee tries to charge a customer for a flavor, without having purchased a drink, it will give an error, because flavors only come in the drinks. Another example would be a restaurant that charges extra for whipped cream and a cherry on top of an ice cream. The register programming would not allow the whipped cream and cherry unless the ice cream had been entered first. Another example is at a fast food place. If you want, say, no onions on your burger, you would have to ring up the burger before you could ring up the "no onions".
On many receipts, I have seen the flavor (or other optional items) slightly indented, to signify that they belong with the main item... in your case, the espresso.
I hope this helps. Let me know if that's what you were looking for.
Feel free to send me another example.
Here's another that I made up:
I am at a bagel store, and I order a bagel, plus cream cheese. If the cashier tried to ring up the cream cheese before the bagel, the register would not let him/her, because the store doesn't sell cream cheese by itself. The bagel would have to be rung up first, followed by the cream cheese. Additionally, the receipt would likely show the cream cheese indented compared to the rest of the items.
I hope this helps,
Without knowing exactly how that store's register works (or seeing your receipt), I would say that if they put the flavor in before the drink, the register would not accept it, and you would not be charged for the flavor. Yes, you are correct.
If you have the receipt, you can upload it to this question, and I can take a look at it for you. If you can't upload it, do you know if the flavor was listed on the receipt at all? If the flavor wasn't listed, then that proves these examples correct.