Merge pull request #3826 from yebblies/issue12503

Issue 12503 - Bad optimization with scope(success) and return statement