These are chat archives for fthomas/refined

22nd
Jun 2016
Frank S. Thomas
@fthomas
Jun 22 2016 16:56

This issue is driving me crazy:

scala> foo(y)
res5: y.type = 0

scala> foo(y): Int
res6: Int = 42

I'm still looking for the cause of this.

Miles Sabin
@milessabin
Jun 22 2016 17:22
I'm working on it too.
It's an interaction between constant folding and inlining.
Well, that's actually a symptom. I think the root of the issue is that there's a missing deconst somewhere quite early on.
I believe the issue is related to: https://issues.scala-lang.org/browse/SI-8564
The default initialization part is a bit if a red-herring ... it happens quite a bit further down the line.
Frank S. Thomas
@fthomas
Jun 22 2016 17:46
Could you reproduce it in a partest? I even failed at that.
Miles Sabin
@milessabin
Jun 22 2016 17:48
Yes I can.
I have,
class TestClazz  {
  def bar(x: "Hi"): x.type = x

  final val y = "Hi"

  //assert(bar(y) ne null)
  //assert(bar(y) eq y)

  final val z = bar(y)                                                                                                            

  assert(z ne null)
  //assert(z eq y)
}

object Test extends TestClazz with App
In test/files/run.
It still asserts with the final removed from val z.
Frank S. Thomas
@fthomas
Jun 22 2016 19:59
Thanks! I'll play around with that. I guess removing final from z is similar to upcasting it to String and that was also the reason I couldn't reproduce it: assert(foo(y) == 1) upcasted foo(y) to Int