Skip to content

Commit 6ae7082

Browse files
committed
Detect when old accessor is compatible with @binaryAPIAccessor
1 parent 22e600e commit 6ae7082

File tree

2 files changed

+27
-21
lines changed

2 files changed

+27
-21
lines changed

compiler/src/dotty/tools/dotc/inlines/PrepareInlineable.scala

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,13 +110,25 @@ object PrepareInlineable {
110110
s"Annotate ${accessed.name} with `$annot` to generate a stable accessor."
111111
else
112112
s"Annotate ${accessed.name} with `$annot` to make it accessible."
113+
113114
val binaryCompat =
114-
s"""Adding $annot may break binary compatibility if a previous version of this
115-
|library was compiled with Scala 3.0-3.3, Binary compatibility should be checked
116-
|using MiMa. To keep binary you can add the following accessor to ${accessor.owner.showKind} ${accessor.owner.name.stripModuleClassSuffix}:
117-
| @binaryAPI private[${accessor.owner.name.stripModuleClassSuffix}] ${accessorDefTree.show}
118-
|
119-
|""".stripMargin
115+
val accessorClass = AccessProxies.hostForAccessorOf(accessed: Symbol)
116+
val inlineAccessorMatches =
117+
accessor.name == InlineAccessorName(accessed.name.asTermName).expandedName(accessorClass)
118+
if !inlineAccessorMatches then
119+
s"""Adding $annot may break binary compatibility if a previous version of this
120+
|library was compiled with Scala 3.0-3.3, Binary compatibility should be checked
121+
|using MiMa. To keep binary compatibility you can add the following accessor to ${accessor.owner.showKind} ${accessor.owner.name.stripModuleClassSuffix}:
122+
| @binaryAPI private[${accessor.owner.name.stripModuleClassSuffix}] ${accessorDefTree.show}
123+
|
124+
|""".stripMargin
125+
else if !accessed.is(Private) then
126+
s"""Adding $annot may break binary compatibility if a previous version of this
127+
|library was compiled with Scala 3.0-3.3, Binary compatibility should be checked
128+
|using MiMa. To keep binary compatibility you can use @binaryAPIAccessor on
129+
|$accessed.""".stripMargin
130+
else
131+
""
120132
report.warning(em"Generated unstable inline accessor for $accessed defined in ${accessed.owner}.\n\n$solution\n\n$binaryCompat", srcPos)
121133
}
122134

tests/neg-custom-args/fatal-warnings/inline-unstable-accessors.check

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,6 @@
55
|
66
| Annotate valBinaryAPI1 with `@binaryAPIAccessor` to generate a stable accessor.
77
|
8-
| Adding @binaryAPIAccessor may break binary compatibility if a previous version of this
9-
| library was compiled with Scala 3.0-3.3, Binary compatibility should be checked
10-
| using MiMa. To keep binary you can add the following accessor to class A:
11-
| @binaryAPI private[A] final def foo$A$$inline$valBinaryAPI1: Int = this.valBinaryAPI1
12-
|
138
-- Error: tests/neg-custom-args/fatal-warnings/inline-unstable-accessors.scala:10:4 ------------------------------------
149
10 | valBinaryAPI2 + // error
1510
| ^^^^^^^^^^^^^
@@ -19,9 +14,8 @@
1914
|
2015
| Adding @binaryAPI may break binary compatibility if a previous version of this
2116
| library was compiled with Scala 3.0-3.3, Binary compatibility should be checked
22-
| using MiMa. To keep binary you can add the following accessor to class A:
23-
| @binaryAPI private[A] def foo$A$$inline$valBinaryAPI2: Int = this.valBinaryAPI2
24-
|
17+
| using MiMa. To keep binary compatibility you can use @binaryAPIAccessor on
18+
| val valBinaryAPI2.
2519
-- Error: tests/neg-custom-args/fatal-warnings/inline-unstable-accessors.scala:15:6 ------------------------------------
2620
15 | a.valBinaryAPI2 + // error
2721
| ^^^^^^^^^^^^^^^
@@ -31,7 +25,7 @@
3125
|
3226
| Adding @binaryAPI may break binary compatibility if a previous version of this
3327
| library was compiled with Scala 3.0-3.3, Binary compatibility should be checked
34-
| using MiMa. To keep binary you can add the following accessor to class B:
28+
| using MiMa. To keep binary compatibility you can add the following accessor to class B:
3529
| @binaryAPI private[B] def inline$valBinaryAPI2$i1(x$0: foo.A): Int = x$0.valBinaryAPI2
3630
|
3731
-- Error: tests/neg-custom-args/fatal-warnings/inline-unstable-accessors.scala:24:4 ------------------------------------
@@ -43,7 +37,7 @@
4337
|
4438
| Adding @binaryAPIAccessor may break binary compatibility if a previous version of this
4539
| library was compiled with Scala 3.0-3.3, Binary compatibility should be checked
46-
| using MiMa. To keep binary you can add the following accessor to class C:
40+
| using MiMa. To keep binary compatibility you can add the following accessor to class C:
4741
| @binaryAPI private[C] final def inline$valBinaryAPI1: Int = this.valBinaryAPI1
4842
|
4943
-- Error: tests/neg-custom-args/fatal-warnings/inline-unstable-accessors.scala:25:4 ------------------------------------
@@ -55,7 +49,7 @@
5549
|
5650
| Adding @binaryAPI may break binary compatibility if a previous version of this
5751
| library was compiled with Scala 3.0-3.3, Binary compatibility should be checked
58-
| using MiMa. To keep binary you can add the following accessor to class C:
52+
| using MiMa. To keep binary compatibility you can add the following accessor to class C:
5953
| @binaryAPI private[C] def inline$valBinaryAPI2: Int = this.valBinaryAPI2
6054
|
6155
-- Error: tests/neg-custom-args/fatal-warnings/inline-unstable-accessors.scala:30:6 ------------------------------------
@@ -67,7 +61,7 @@
6761
|
6862
| Adding @binaryAPI may break binary compatibility if a previous version of this
6963
| library was compiled with Scala 3.0-3.3, Binary compatibility should be checked
70-
| using MiMa. To keep binary you can add the following accessor to class D:
64+
| using MiMa. To keep binary compatibility you can add the following accessor to class D:
7165
| @binaryAPI private[D] def inline$valBinaryAPI2$i2(x$0: foo.C): Int = x$0.valBinaryAPI2
7266
|
7367
-- Error: tests/neg-custom-args/fatal-warnings/inline-unstable-accessors.scala:39:4 ------------------------------------
@@ -79,7 +73,7 @@
7973
|
8074
| Adding @binaryAPIAccessor may break binary compatibility if a previous version of this
8175
| library was compiled with Scala 3.0-3.3, Binary compatibility should be checked
82-
| using MiMa. To keep binary you can add the following accessor to object E:
76+
| using MiMa. To keep binary compatibility you can add the following accessor to object E:
8377
| @binaryAPI private[E] final def inline$valBinaryAPI1: Int = foo.E.valBinaryAPI1
8478
|
8579
-- Error: tests/neg-custom-args/fatal-warnings/inline-unstable-accessors.scala:40:4 ------------------------------------
@@ -91,7 +85,7 @@
9185
|
9286
| Adding @binaryAPI may break binary compatibility if a previous version of this
9387
| library was compiled with Scala 3.0-3.3, Binary compatibility should be checked
94-
| using MiMa. To keep binary you can add the following accessor to object E:
88+
| using MiMa. To keep binary compatibility you can add the following accessor to object E:
9589
| @binaryAPI private[E] def inline$valBinaryAPI2: Int = foo.E.valBinaryAPI2
9690
|
9791
-- Error: tests/neg-custom-args/fatal-warnings/inline-unstable-accessors.scala:45:6 ------------------------------------
@@ -103,6 +97,6 @@
10397
|
10498
| Adding @binaryAPI may break binary compatibility if a previous version of this
10599
| library was compiled with Scala 3.0-3.3, Binary compatibility should be checked
106-
| using MiMa. To keep binary you can add the following accessor to object F:
100+
| using MiMa. To keep binary compatibility you can add the following accessor to object F:
107101
| @binaryAPI private[F] def inline$valBinaryAPI2$i3(x$0: foo.E): Int = x$0.valBinaryAPI2
108102
|

0 commit comments

Comments
 (0)