I know that unity overloaded null, maybe equals also, for several reasons. you are, somehow, successfully using the constructor on the returned AudioSource. maybe it creates a new instance but overrides null so that it’s not pointing to any legal C++ native component anymore effectively comparing nulls.
don’t use new on any unity class. use AddComponent if you need another.
I did some research and found, truly like @hexagonius said, unity overrided something like Equals, == and != to build a Null Object pattern.
So here is my code to test:
It looks like GetComponent will always return reference of a T type instance if T is a NATIVE component type, whether or not there is a T component attached to the gameobject.
But when you want to get a custom component, if there is no one attached, GetComponent will definitely return a real null. Like this:
GameDataState _GameDataState = new GameObject().GetComponent<GameDataState>();
Debug.Log(object.Equals(_GameDataState, null));
Debug.Log(_GameDataState.enabled);
Debug.Log("Pass");
It would yield a NullReferenceException.
So you can see unity overrided some method to make you think it’s null when you try to get a not attached component, and i think maybe they forgot to deal with this PlayOneShot method so it can be invoked.