Comments (2)
Given
class A; object A1 extends A
class B; object B1 extends B; object B2 extends B
class C; object C1 extends C
object T {
def t = {
val x = new Foo(A1, B1)
x.copy(b = B2)
}
}
Version 1
Foo defined as:
final class Foo(a: A, b: B) {
def copy(a: A = a , b: B = b) = new Foo(a, b)
}
Then the final bytecode contains these:
<synthetic> def copy$default$1(): A = Foo.this.a;
<synthetic> def copy$default$2(): B = Foo.this.b;
def t(): Foo = {
val x: Foo = new Foo(A1, B1);
{
<artifact> val x$1: B2.type = B2;
<artifact> val x$2: A = x.copy$default$1();
x.copy(x$2, x$1)
}
};
Version 2
Add a parameter at the front and overload:
final class Foo(c: C, a: A, b: B) {
def this(a: A, b: B) = this(C1, a, b)
def copy(a: A, b: B) = new Foo(c, a, b)
def copy(c: C = c, a: A = a, b: B = b) = new Foo(c, a, b)
}
Then you get:
<synthetic> def copy$default$1(): C = Foo.this.c;
<synthetic> def copy$default$2(): A = Foo.this.a;
<synthetic> def copy$default$3(): B = Foo.this.b;
def t(): Foo = {
val x: Foo = new Foo(A1, B1);
{
<artifact> val x$1: B2.type = B2;
<artifact> val x$2: C = x.copy$default$1();
<artifact> val x$3: A = x.copy$default$2();
x.copy(x$2, x$3, x$1)
}
};
Note
copy$default$1
and copy$default$2
have new, completely incompatible types.
This would:
- fail MiMa
- fail with a
ClassCastException
at runtime (or some other fatal error), and - requires a recompilation to fix.
from contraband.
I checked, and my assumption was wrong: MiMa doesn't fail..
Opened lightbend/mima#136
from contraband.
Related Issues (20)
- Support for rudimentary optics
- Generated code causes compiler warnings HOT 1
- Generate Shapeless Generic instances HOT 5
- Can't define singleton types
- maven plugin
- equal / hashCode inconsistencies around Array HOT 1
- always use \n for line breaks HOT 5
- Is it possible to define a Map within a type? HOT 1
- Incorrect Scaladoc
- Allow modifier to be changed from final class to sealed class
- use "boxed type".hashCode(value) instead of "boxed type".valueOf(value).hashCode() HOT 1
- Identifier conflict on "js" field when generating JSON codec with sjson new
- gh-pages could use a publish HOT 1
- +generateContrabands doesn't work with crossScalaVersions HOT 2
- Does Contraband Generated No-Arg Constructors for Java POJOs HOT 3
- Cannot resolve symbol ScalaKeywords
- Some generated code does not compile with -Xfatal-warnings
- Allow sealed interface
- Travis CI dropped
- self type specification is not enough for Scala 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from contraband.