File tree Expand file tree Collapse file tree 1 file changed +24
-1
lines changed
docs/docs/reference/other-new-features Expand file tree Collapse file tree 1 file changed +24
-1
lines changed Original file line number Diff line number Diff line change @@ -56,8 +56,31 @@ def f(x: => Int): Int = x + 1 // OK
5656```
5757This will produce methods ` f_string ` and ` f ` in the generated code.
5858
59+ However, ` @targetName ` annotations are not allowed to break overriding relationships
60+ between two definitions that have otherwise the same names and types. So the following would be in error:
61+ ``` scala
62+ import annotation .targetName
63+ class A :
64+ def f (): Int = 1
65+ class B extends A :
66+ targetName(" g" ) def f (): Int = 2
67+ ```
68+ The compiler reports here:
69+ ```
70+ -- Error: test.scala:6:23 ------------------------------------------------------
71+ 6 | @targetName("g") def f(): Int = 2
72+ | ^
73+ |error overriding method f in class A of type (): Int;
74+ | method f of type (): Int should not have a @targetName annotation since the overridden member hasn't one either
75+ ```
76+ The relevant overriding rules can be summarized as follows:
77+
78+ - Two members can override each other if their names and signatures are the same,
79+ and they either have the same erased names or the same types.
80+ - If two members override, then both their erased names and their types must be the same.
81+
5982As usual, any overriding relationship in the generated code must also
60- be present in the original code. So the following example would be in error:
83+ be present in the original code. So the following example would also be in error:
6184``` scala
6285import annotation .targetName
6386class A :
You can’t perform that action at this time.
0 commit comments