Use case instead of if.
Use val instead of var. Improved warning message.