@@ -955,14 +955,24 @@ class CodeGen(schema: Schema) {
955
955
956
956
val propertyDefaultValues = propertyDefaultValueImpl(s " $className.PropertyDefaults " , properties)
957
957
958
- s """ class $className(graph : Graph, id : Long) extends NodeRef[ $classNameDb](graph, id )
958
+ s """ class $className(graph_4762 : Graph, id_4762 : Long /*cf https://github.com/scala/bug/issues/4762 */ ) extends NodeRef[ $classNameDb](graph_4762, id_4762 )
959
959
| with ${className}Base
960
960
| with StoredNode
961
961
| $mixinsForExtendedNodes {
962
962
| $propertyDelegators
963
963
| $propertyDefaultValues
964
964
| $delegatingContainedNodeAccessors
965
965
| $neighborAccessorDelegators
966
+ | // In view of https://github.com/scala/bug/issues/4762 it is advisable to use different variable names in
967
+ | // patterns like `class Base(x:Int)` and `class Derived(x:Int) extends Base(x)`.
968
+ | // This must become `class Derived(x_4762:Int) extends Base(x_4762)`.
969
+ | // Otherwise, it is very hard to figure out whether uses of the identifier `x` refer to the base class x
970
+ | // or the derived class x.
971
+ | // When using that pattern, the class parameter `x_47672` should only be used in the `extends Base(x_4762)`
972
+ | // clause and nowhere else. Otherwise, the compiler may well decide that this is not just a constructor
973
+ | // parameter but also a field of the class, and we end up with two `x` fields. At best, this wastes memory;
974
+ | // at worst both fields go out-of-sync for hard-to-debug correctness bugs.
975
+ |
966
976
|
967
977
| override def fromNewNode(newNode: NewNode, mapping: NewNode => StoredNode): Unit = get().fromNewNode(newNode, mapping)
968
978
| override def canEqual(that: Any): Boolean = get.canEqual(that)
0 commit comments