Why I got an error msg?

Hello guys I’m new to Kotlin and I want some help

Why I got an error from code 2 and I don’t get it from code 1

Code 1

var num:Short = 10 + 10

Code 2

var num:Short = 10
var num2:Short = num + 10

The compiler is warning you that you’re trying to implicitly use an Int expression as a Short. I suppose that the compiler knows that 10+10 can be safely used as a Short, but num+10 might not fit into a Short. (If this logic is faulty, please correct me.)

Two solutions:

Make num2 an Int:
var num2: Int = num + 10

Or explicitly convert the expression to Short:
var num2:Short = (num + 10).toShort()

Stupid Compiler :expressionless:
I also get an error msg when I try :slight_smile:

var num:Short = 10
var num2:Short = 10
var num3:Short = num + num2

According to the documentation that is the correct result.

Ok thx bro , I thought it an error