Skip to content

work around scala bug 4762 #205

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

Merged
merged 3 commits into from
Feb 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion codegen/src/main/scala/overflowdb/codegen/CodeGen.scala
Original file line number Diff line number Diff line change
Expand Up @@ -955,14 +955,24 @@ class CodeGen(schema: Schema) {

val propertyDefaultValues = propertyDefaultValueImpl(s"$className.PropertyDefaults", properties)

s"""class $className(graph: Graph, id: Long) extends NodeRef[$classNameDb](graph, id)
s"""class $className(graph_4762: Graph, id_4762: Long /*cf https://github.com/scala/bug/issues/4762 */) extends NodeRef[$classNameDb](graph_4762, id_4762)
| with ${className}Base
| with StoredNode
| $mixinsForExtendedNodes {
| $propertyDelegators
| $propertyDefaultValues
| $delegatingContainedNodeAccessors
| $neighborAccessorDelegators
| // In view of https://github.com/scala/bug/issues/4762 it is advisable to use different variable names in
| // patterns like `class Base(x:Int)` and `class Derived(x:Int) extends Base(x)`.
| // This must become `class Derived(x_4762:Int) extends Base(x_4762)`.
| // Otherwise, it is very hard to figure out whether uses of the identifier `x` refer to the base class x
| // or the derived class x.
| // When using that pattern, the class parameter `x_47672` should only be used in the `extends Base(x_4762)`
| // clause and nowhere else. Otherwise, the compiler may well decide that this is not just a constructor
| // parameter but also a field of the class, and we end up with two `x` fields. At best, this wastes memory;
| // at worst both fields go out-of-sync for hard-to-debug correctness bugs.
|
|
| override def fromNewNode(newNode: NewNode, mapping: NewNode => StoredNode): Unit = get().fromNewNode(newNode, mapping)
| override def canEqual(that: Any): Boolean = get.canEqual(that)
Expand Down
3 changes: 3 additions & 0 deletions integration-tests/tests/src/test/scala/Schema01Test.scala
Original file line number Diff line number Diff line change
Expand Up @@ -97,5 +97,8 @@ class Schema01Test extends AnyWordSpec with Matchers {
innerNode.get shouldBe node3
}
}
"work around scala bug 4762, ie generate no extraneous fields" in {
Class.forName("testschema01.nodes.Node1").getDeclaredFields.length shouldBe 0
}

}