This is my clumsy attempt to exploit the fact that the new pattern matcher does not store case class members in local variables, but instead it goes through getters each time it's referenced in the rhs.
For a while I thought it is only annoying when debugging, until I realized that case classes can have mutable members. So here is a ClassCastException based on the fact that the type checker assumes pattern-bound identifiers to be stable:
abstractclassBomb {
typeTvalx:Tdefsize(that: T):Int
}
classStringBombextendsBomb {
typeT=Stringvalx="abc"defsize(that: String):Int= that.length
}
classIntBombextendsBomb {
typeT=Intvalx=10defsize(that: Int) = x + that
}
caseclassMean(varbomb:Bomb)
objectMainextendsApp {
deffoo(x: Mean) = x match {
caseMean(b) =>// b is assumed to be a stable identifier, but it can actually be mutated
println(b.size({ mutate(); b.x }))
}
defmutate() {
m.bomb =newIntBomb
}
valm=Mean(newStringBomb)
foo(m)
}
The text was updated successfully, but these errors were encountered:
This is my clumsy attempt to exploit the fact that the new pattern matcher does not store case class members in local variables, but instead it goes through getters each time it's referenced in the rhs.
For a while I thought it is only annoying when debugging, until I realized that case classes can have mutable members. So here is a
ClassCastExceptionbased on the fact that the type checker assumes pattern-bound identifiers to be stable:The text was updated successfully, but these errors were encountered: