AtomicKotlinExamples icon indicating copy to clipboard operation
AtomicKotlinExamples copied to clipboard

[book] Type Inference (type rules) algorithm

Open storenth opened this issue 1 year ago • 0 comments

From the book at Number Types

The location where the L appears is unimportant. If one of the values is Long, the resulting expression is Long.

https://github.com/BruceEckel/AtomicKotlinExamples/blob/18d4e8913ad80df41ea474af9b8987266771c8f4/Examples/NumberTypes/UsingLongs.kt#L6

Not true, there is an actual result in case I move L val to the different place:

fun main() {
  val i = Int.MAX_VALUE
  println(i + i + 0L)  // overflow, because of math rule
}
type-rule

Anyway, can you explain Type Inference (type rules) algo or point me to an authoritative resource?

storenth avatar Apr 19 '23 13:04 storenth