lunduniversity / introprog

Teaching material for "Introduction to Programming using Scala" at Lund University, LTH. http://cs.lth.se/pgk/
142 stars 177 forks source link

Scala 2 differs from 3 with forward declarations #662

Closed marcusklang closed 2 years ago

marcusklang commented 2 years ago
{
   val b = a;
   val a = 42;
}

Compiles and works, but in Scala 2 you were given a warning. In Scala 3 you are not given a warning.

b is given the value 0.

Update compendium answers for exercise 4.2 to reflect changes.

bjornregnell commented 2 years ago

https://docs.scala-lang.org/scala3/reference/other-new-features/safe-initialization.html

bjornregnell commented 2 years ago

https://github.com/lampepfl/dotty/issues/16083