From your comment on Line 21, S and Y extends X, but S doesn't seem to be a subtype of Y. So on line 23, it would give a compile time error as object 's' cannot be returned where an instance of Y or its subtype is expected.
Don't get me started about those stupid light bulbs.