-
Notifications
You must be signed in to change notification settings - Fork 53
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Issue with this in presence of self alias + & types #99
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code seems more readable to me now.
modified.a shouldBe 1 | ||
} | ||
|
||
// TODO this is an implemenation limitation for now, since anonymous classes crash on runtime |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
limitation of quicklens, Scala 3? If the latter, is there a dotty ticket maybe?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
limitation of quicklens, Scala 3?
quicklens
. I think.
I'm not sure if there should be a dotty ticket for it since we're using asInstanceOf
.
Also, the problem occurs only for the last two tests - the ones with anonymous classes.
It's not hard to minimize, because we can just type the generated code by hand:
sealed trait T
case class A(a: Int) extends T
trait B {
def a: Int
}
val ab: T & B = new A(0) with B
val res: T & B = // if we change the ascription to `A & B` it works
if(ab.isInstanceOf[A]) then {
ab.asInstanceOf[A].copy().asInstanceOf[A & B]
} else {
???
}
Scastie: https://scastie.scala-lang.org/KacperFKorban/s7A3euoTST2AoPYcTug8iA/5
Maybe there is some other way to write it so that it won't crash on runtime 🤔
The only weird thing is that it doesn't crash if we change the type ascription to the more specific one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note: when I rewrite this using with
instead of ¨&` and try it with Scala 2.13, it works: https://scastie.scala-lang.org/0vAFV0B8SDmZrjvbRj3jsA
The same code with with
still does not work in Scala 3.
To me this looks like a Scala 3 bug.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reported in scala/scala3#15952
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok so now that we know it's a quicklens not a dotty issue, can we do anything about it? :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't see an immediate solution. The problem is in the generated bytecode, so no matter what we do ab.asInstanceOf[A].copy()
will have to be cast to T & B
. Which is impossible.
Also if we want to have a discussion about it, maybe a new issue will be a better place for it 😃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure :) #100
Thanks :) |
Continuation of #98