-
Notifications
You must be signed in to change notification settings - Fork 21
Closed
Labels
Description
@gafiatulin did come over a strange behaviour when constructing a class where the first argument used ticks and a special character and the second was the same up to the special character, for instance:
scala> case class A(`a-b`: Int, a: Int)
defined class A
scala> A(1, 2)
res0: A = A(1,1)
This applies to both class and case classes but not functions. From the decompiled code below you can see that it does assign the second variable to the wrong value. If the values isn't compatible you will get a runtime error.
class B(`a-b`: Int, a: Int){ override def toString = s"${`a-b`} $a"}
decompiles to:
public class B {
private final int a$minusb;
private final int a;
public String toString() {
return new StringContext((Seq)Predef$.MODULE$.wrapRefArray((Object[])new String[]{"", " ", ""})).s((Seq)Predef$.MODULE$.genericWrapArray((Object)new Object[]{BoxesRunTime.boxToInteger((int)this.a$minusb), BoxesRunTime.boxToInteger((int)this.a)}));
}
public B(int a$minusb, int a) {
this.a$minusb = a$minusb;
this.a = a$minusb;
}
}