Teaching my Child to Share... or Not?

One of the first things that I was taught as a child was to share. The family mantra 'sharing is caring' still echoes in my ear and I remember how my parents and grandparents always stressed the importance of sharing. A rather uncomfortable situation last week, made me rethink how I want to rightly imbibe this virtue in my son, without it becoming something that has just been passed down from generations.
Ever since my son has been able to comprehend instructions, I have yelled the same mantra over and over again, everywhere we go: 'sharing is caring', 'you must learn to share', 'always share'. It's probably tattooed in his mind because every time someone hands him a chocolate or anything for that matter, he feels the need to share and it doesn't matter who. I'm quite elated when he does this but this incident left me wondering if I need to alter the mantra to include a disclaimer that gives him the right to choose if he wants to share or not, depending on the situation.
A few days back, while we were on our way to the park, my son suddenly walked up to an unknown little boy and offered him the toy he was holding. While I was quite stumped at his gesture, I did not have the heart to stop him but I bent over and asked him if he really wanted to share. Yes, I didn't even think if  it was the right think to do and this was not my 'greatest' parenting moment. Asking a toddler rational questions is quite literally similar to having a brick fall on your toes. My son was quite sure he wanted to give that toy away. So I didn't argue and we walked away but I was absolutely confused about how I had reacted.
In my mind, the situation did not warrant sharing. The other child hadn't even asked or wanted that toy and yet my son voluntarily gave it up. It's nice in a way but in future, I certainly don't want him to be taken advantage of. 
I think we see a lot of bullying these days and unfortunately I was a victim of a nasty bully when I was in grade three. I don't remember being bold enough to say 'no' to the many unreasonable requests that made me feel I was obligated to share. As a mom, I think it's mostly because I wasn't given that disclaimer. That's why I think it's important to teach my son how to say 'no', even to share something if he feels uncomfortable in a particular situation. I never want my son to be bullied just because he's the one who tops the charts when it comes to sharing. I want him to learn why and when exactly he needs to share and not because it's always the right thing to do. I want him to share his toys but if he's being forced to, then I want him to know that's it's okay to disagree, that he won't be less virtuous because he didn't willingly give it up. I know my instincts are right so it's my gut feeling and I'm going with it.
Have you ever faced a similar situation? Would love to hear your thoughts on how you would approach this subject with your child. Thanks for taking the time to read.