Skip to content

Commit 17a0429

Browse files
committed
Fix #4754: Don't generate inline accessor for constants
1 parent d761815 commit 17a0429

File tree

3 files changed

+21
-5
lines changed

3 files changed

+21
-5
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ object PostTyper {
1717

1818
/** A macro transform that runs immediately after typer and that performs the following functions:
1919
*
20-
* (1) Add super accessors and protected accessors (@see SuperAccessors)
20+
* (1) Add super accessors (@see SuperAccessors)
2121
*
2222
* (2) Convert parameter fields that have the same name as a corresponding
2323
* public parameter field in a superclass to a forwarder to the superclass

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ object Inliner {
4848
def accessorNameKind = InlineAccessorName
4949

5050
/** A definition needs an accessor if it is private, protected, or qualified private
51-
* and it is not part of the tree that gets inlined. The latter test is implemented
52-
* by excluding all symbols properly contained in the inlined method.
53-
*/
51+
* and it is not part of the tree that gets inlined. The latter test is implemented
52+
* by excluding all symbols properly contained in the inlined method.
53+
*
54+
* Constant vals don't need accessors since they are inlined in FirstTransform.
55+
*/
5456
def needsAccessor(sym: Symbol)(implicit ctx: Context) =
5557
sym.isTerm &&
5658
(sym.is(AccessFlags) || sym.privateWithin.exists) &&
57-
!sym.isContainedIn(inlineSym)
59+
!sym.isContainedIn(inlineSym) &&
60+
!(sym.isStable && sym.info.widenTermRefExpr.isInstanceOf[ConstantType])
5861

5962
def preTransform(tree: Tree)(implicit ctx: Context): Tree
6063

tests/pos/i4754.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
object Foo {
2+
private final val x = 1
3+
private def y = 2
4+
}
5+
6+
class Foo {
7+
import Foo._
8+
inline def foo = x + Foo.x + y + Foo.y
9+
}
10+
11+
class Test {
12+
(new Foo).foo
13+
}

0 commit comments

Comments
 (0)