On 04.06.20 21:45, Daniil Ovchinnikov wrote:
[...]
  If we do not give up on flow typing, then I would like to
know why the assignment should not be legal. And if it is legal in the
if-branch, then why not in the Closure block?

All assignments should be legal, and assignment in Closure block as well.

to be clear. An assignment should be legal if the flow type of a
variable and the static type of a variable are compatible. The new type
of the variable is then the flow type (in Java it would stay being the
static type).

Let me annotate the last example with types:

class A {}
class B extends A{ def b() {}}
class C extends A{}

A x // inferred to A because LUB(B,C) = A
x = new B()
// typeOf(x) as this point is B due to flow typing
if (true) {
     x = new C()
     // typeOf(x) as this point is C due to flow typing
}
// typeOf(x) as this point is A due to flow typing merging branches where 
typeOf(x) is B and C
A z  // inferred to A because LUB(A) = A
z = x
// typeOf(z) as this point is A
z.b() // STC error, no method b in A

Which means we are on the same page, only that you work with LUB and I
with LUBU. I know LUBU is a difficult thing. Not really in
understanding, but in teaching the JVM, the compiler and the IDEs. The
"normal" LUB is much more easy here.

bye Jochen

Reply via email to